mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
use new actix crates
This commit is contained in:
parent
9f4d48f7a1
commit
aaae368ed9
56
Cargo.toml
56
Cargo.toml
@ -28,61 +28,55 @@ name = "actix_http"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = ["session", "cell"]
|
||||
default = ["session"]
|
||||
|
||||
# sessions feature, session require "ring" crate and c compiler
|
||||
session = ["cookie/secure"]
|
||||
|
||||
cell = ["actix-net/cell"]
|
||||
|
||||
# tls
|
||||
tls = ["native-tls", "actix-net/tls"]
|
||||
|
||||
# openssl
|
||||
ssl = ["openssl", "actix-net/ssl"]
|
||||
|
||||
# rustls
|
||||
rust-tls = ["rustls", "actix-net/rust-tls"]
|
||||
ssl = ["openssl", "actix-connector/ssl"]
|
||||
|
||||
[dependencies]
|
||||
actix = "0.7.5"
|
||||
#actix-net = "0.3.0"
|
||||
actix-net = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-service = "0.1.1"
|
||||
actix-codec = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-connector = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-rt = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-server = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-utils = { git="https://github.com/actix/actix-net.git" }
|
||||
|
||||
# actix-codec = { path="../actix-net/actix-codec/" }
|
||||
# actix-connector = { path="../actix-net/actix-connector/" }
|
||||
# actix-rt = { path="../actix-net/actix-rt/" }
|
||||
# actix-server = { path="../actix-net/actix-server/" }
|
||||
# actix-utils = { path="../actix-net/actix-utils/" }
|
||||
|
||||
base64 = "0.9"
|
||||
bitflags = "1.0"
|
||||
bytes = "0.4"
|
||||
byteorder = "1.2"
|
||||
cookie = { version="0.11", features=["percent-encode"] }
|
||||
encoding = "0.2"
|
||||
failure = "0.1.3"
|
||||
futures = "0.1"
|
||||
http = "0.1.8"
|
||||
httparse = "1.3"
|
||||
failure = "0.1.3"
|
||||
indexmap = "1.0"
|
||||
log = "0.4"
|
||||
mime = "0.3"
|
||||
net2 = "0.2"
|
||||
percent-encoding = "1.0"
|
||||
rand = "0.5"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
sha1 = "0.6"
|
||||
time = "0.1"
|
||||
encoding = "0.2"
|
||||
serde_urlencoded = "0.5.3"
|
||||
|
||||
cookie = { version="0.11", features=["percent-encode"] }
|
||||
percent-encoding = "1.0"
|
||||
url = { version="1.7", features=["query_encoding"] }
|
||||
|
||||
# io
|
||||
net2 = "0.2"
|
||||
slab = "0.4"
|
||||
bytes = "0.4"
|
||||
byteorder = "1.2"
|
||||
futures = "0.1"
|
||||
tokio-codec = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-io = "0.1"
|
||||
serde_urlencoded = "0.5.3"
|
||||
time = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
tokio-timer = "0.2"
|
||||
tokio-current-thread = "0.1"
|
||||
trust-dns-proto = "0.5.0"
|
||||
trust-dns-resolver = "0.10.0"
|
||||
url = { version="1.7", features=["query_encoding"] }
|
||||
|
||||
# native-tls
|
||||
native-tls = { version="0.2", optional = true }
|
||||
|
@ -1,27 +1,18 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
extern crate http;
|
||||
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{h1, Request, Response};
|
||||
use actix_net::server::Server;
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_server::Server;
|
||||
use actix_service::NewService;
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
Server::new()
|
||||
Server::build()
|
||||
.bind("echo", "127.0.0.1:8080", || {
|
||||
h1::H1Service::build()
|
||||
.client_timeout(1000)
|
||||
|
@ -1,19 +1,11 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
|
||||
use actix_http::http::HeaderValue;
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{h1, Error, Request, Response};
|
||||
use actix_net::server::Server;
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_server::Server;
|
||||
use actix_service::NewService;
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn handle_request(_req: Request) -> impl Future<Item = Response, Error = Error> {
|
||||
@ -29,7 +21,7 @@ fn main() {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
Server::new()
|
||||
Server::build()
|
||||
.bind("echo", "127.0.0.1:8080", || {
|
||||
h1::H1Service::build()
|
||||
.client_timeout(1000)
|
||||
|
@ -1,18 +1,9 @@
|
||||
extern crate env_logger;
|
||||
extern crate log;
|
||||
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
extern crate http;
|
||||
|
||||
use actix_codec::Framed;
|
||||
use actix_http::{h1, Response, SendResponse, ServiceConfig};
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::framed::IntoFramed;
|
||||
use actix_net::server::Server;
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_net::stream::TakeItem;
|
||||
use actix_server::Server;
|
||||
use actix_service::NewService;
|
||||
use actix_utils::framed::IntoFramed;
|
||||
use actix_utils::stream::TakeItem;
|
||||
use futures::Future;
|
||||
use std::env;
|
||||
|
||||
@ -20,7 +11,7 @@ fn main() {
|
||||
env::set_var("RUST_LOG", "framed_hello=info");
|
||||
env_logger::init();
|
||||
|
||||
Server::new()
|
||||
Server::build()
|
||||
.bind("framed_hello", "127.0.0.1:8080", || {
|
||||
IntoFramed::new(|| h1::Codec::new(ServiceConfig::default()))
|
||||
.and_then(TakeItem::new().map_err(|_| ()))
|
||||
|
@ -1,24 +1,16 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate env_logger;
|
||||
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate futures;
|
||||
extern crate http;
|
||||
|
||||
use actix_http::{h1, Response};
|
||||
use actix_net::server::Server;
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_server::Server;
|
||||
use actix_service::NewService;
|
||||
use futures::future;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
env::set_var("RUST_LOG", "hello_world=info");
|
||||
env_logger::init();
|
||||
|
||||
Server::new()
|
||||
Server::build()
|
||||
.bind("hello-world", "127.0.0.1:8080", || {
|
||||
h1::H1Service::build()
|
||||
.client_timeout(1000)
|
||||
|
@ -1,5 +1,4 @@
|
||||
use actix_net::connector::RequestPort;
|
||||
use actix_net::resolver::RequestHost;
|
||||
use actix_connector::{RequestHost, RequestPort};
|
||||
use http::uri::Uri;
|
||||
use http::{Error as HttpError, HttpTryFrom};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{fmt, io, time};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use futures::Poll;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::pool::Acquired;
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
use std::time::Duration;
|
||||
use std::{fmt, io};
|
||||
|
||||
use actix_net::connector::TcpConnector;
|
||||
use actix_net::resolver::Resolver;
|
||||
use actix_net::service::{Service, ServiceExt};
|
||||
use actix_net::timeout::{TimeoutError, TimeoutService};
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_connector::{Resolver, TcpConnector};
|
||||
use actix_service::Service;
|
||||
use actix_utils::timeout::{TimeoutError, TimeoutService};
|
||||
use futures::future::Either;
|
||||
use futures::Poll;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||
|
||||
use super::connect::Connect;
|
||||
@ -16,7 +15,7 @@ use super::error::ConnectorError;
|
||||
use super::pool::ConnectionPool;
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
use actix_net::ssl::OpensslConnector;
|
||||
use actix_connector::ssl::OpensslConnector;
|
||||
#[cfg(feature = "ssl")]
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
|
||||
@ -169,7 +168,7 @@ impl Connector {
|
||||
.and_then(TcpConnector::default().from_err())
|
||||
.and_then(
|
||||
OpensslConnector::service(self.connector)
|
||||
.map_err(ConnectorError::SslError),
|
||||
.map_err(ConnectorError::from),
|
||||
),
|
||||
)
|
||||
.map_err(|e| match e {
|
||||
|
@ -4,13 +4,7 @@ use failure::Fail;
|
||||
use trust_dns_resolver::error::ResolveError;
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
use openssl::ssl::Error as SslError;
|
||||
|
||||
#[cfg(all(feature = "tls", not(any(feature = "ssl", feature = "rust-tls"))))]
|
||||
use native_tls::Error as SslError;
|
||||
|
||||
#[cfg(all(feature = "rust-tls", not(any(feature = "tls", feature = "ssl"))))]
|
||||
use std::io::Error as SslError;
|
||||
use openssl::ssl::{Error as SslError, HandshakeError};
|
||||
|
||||
use crate::error::{Error, ParseError};
|
||||
|
||||
@ -26,7 +20,7 @@ pub enum ConnectorError {
|
||||
SslIsNotSupported,
|
||||
|
||||
/// SSL error
|
||||
#[cfg(any(feature = "tls", feature = "ssl", feature = "rust-tls"))]
|
||||
#[cfg(feature = "ssl")]
|
||||
#[fail(display = "{}", _0)]
|
||||
SslError(#[cause] SslError),
|
||||
|
||||
@ -73,6 +67,28 @@ impl From<ResolveError> for ConnectorError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
impl From<SslError> for ConnectorError {
|
||||
fn from(err: SslError) -> ConnectorError {
|
||||
ConnectorError::SslError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
impl<T> From<HandshakeError<T>> for ConnectorError {
|
||||
fn from(err: HandshakeError<T>) -> ConnectorError {
|
||||
match err {
|
||||
HandshakeError::SetupFailure(stack) => SslError::from(stack).into(),
|
||||
HandshakeError::Failure(stream) => {
|
||||
SslError::from(stream.into_error()).into()
|
||||
}
|
||||
HandshakeError::WouldBlock(stream) => {
|
||||
SslError::from(stream.into_error()).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of errors that can occur during request sending and response reading
|
||||
#[derive(Debug)]
|
||||
pub enum SendRequestError {
|
||||
|
@ -1,11 +1,10 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::Service;
|
||||
use bytes::Bytes;
|
||||
use futures::future::{err, ok, Either};
|
||||
use futures::{Async, Future, Poll, Sink, Stream};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::error::{ConnectorError, SendRequestError};
|
||||
use super::response::ClientResponse;
|
||||
|
@ -4,7 +4,9 @@ use std::io;
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_rt::spawn;
|
||||
use actix_service::Service;
|
||||
use futures::future::{ok, Either, FutureResult};
|
||||
use futures::sync::oneshot;
|
||||
use futures::task::AtomicTask;
|
||||
@ -12,8 +14,6 @@ use futures::{Async, Future, Poll};
|
||||
use http::uri::Authority;
|
||||
use indexmap::IndexSet;
|
||||
use slab::Slab;
|
||||
use tokio_current_thread::spawn;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::{sleep, Delay};
|
||||
|
||||
use super::connect::Connect;
|
||||
|
@ -2,7 +2,7 @@ use std::fmt;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::io::Write;
|
||||
|
||||
use actix_net::service::Service;
|
||||
use actix_service::Service;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use cookie::{Cookie, CookieJar};
|
||||
use futures::{Future, Stream};
|
||||
@ -23,26 +23,24 @@ use super::{pipeline, Connect, Connection, ConnectorError, SendRequestError};
|
||||
/// An HTTP Client Request
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # use futures::Future;
|
||||
/// # use std::process;
|
||||
/// use actix_web::{actix, client};
|
||||
/// use futures::future::{Future, lazy};
|
||||
/// use actix_rt::System;
|
||||
/// use actix_http::client;
|
||||
///
|
||||
/// fn main() {
|
||||
/// actix::run(
|
||||
/// || client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// System::new("test").block_on(lazy(|| {
|
||||
/// let mut connector = client::Connector::default().service();
|
||||
/// client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// .header("User-Agent", "Actix-web")
|
||||
/// .finish().unwrap()
|
||||
/// .send() // <- Send http request
|
||||
/// .send(&mut connector) // <- Send http request
|
||||
/// .map_err(|_| ())
|
||||
/// .and_then(|response| { // <- server http response
|
||||
/// println!("Response: {:?}", response);
|
||||
/// # actix::System::current().stop();
|
||||
/// # actix_rt::System::current().stop();
|
||||
/// Ok(())
|
||||
/// }),
|
||||
/// );
|
||||
/// })
|
||||
/// }));
|
||||
/// }
|
||||
/// ```
|
||||
pub struct ClientRequest<B: MessageBody = ()> {
|
||||
|
@ -4,11 +4,11 @@ use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{fmt, net};
|
||||
|
||||
use actix_rt::spawn;
|
||||
use bytes::BytesMut;
|
||||
use futures::{future, Future};
|
||||
use log::error;
|
||||
use time;
|
||||
use tokio_current_thread::spawn;
|
||||
use tokio_timer::{sleep, Delay};
|
||||
|
||||
// "Sun, 06 Nov 1994 08:49:37 GMT".len()
|
||||
@ -378,8 +378,8 @@ impl DateService {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_rt::System;
|
||||
use futures::future;
|
||||
use tokio::runtime::current_thread;
|
||||
|
||||
#[test]
|
||||
fn test_date_len() {
|
||||
@ -388,7 +388,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_date() {
|
||||
let mut rt = current_thread::Runtime::new().unwrap();
|
||||
let mut rt = System::new("test");
|
||||
|
||||
let _ = rt.block_on(future::lazy(|| {
|
||||
let settings = ServiceConfig::new(KeepAlive::Os, 0, 0);
|
||||
|
@ -5,7 +5,7 @@ use std::string::FromUtf8Error;
|
||||
use std::sync::Mutex;
|
||||
use std::{fmt, io, result};
|
||||
|
||||
use actix::MailboxError;
|
||||
// use actix::MailboxError;
|
||||
use cookie;
|
||||
use failure::{self, Backtrace, Fail};
|
||||
use futures::Canceled;
|
||||
@ -250,8 +250,8 @@ impl ResponseError for header::InvalidHeaderValueBytes {
|
||||
/// `InternalServerError` for `futures::Canceled`
|
||||
impl ResponseError for Canceled {}
|
||||
|
||||
/// `InternalServerError` for `actix::MailboxError`
|
||||
impl ResponseError for MailboxError {}
|
||||
// /// `InternalServerError` for `actix::MailboxError`
|
||||
// impl ResponseError for MailboxError {}
|
||||
|
||||
/// A set of errors that can occur during parsing HTTP streams
|
||||
#[derive(Fail, Debug)]
|
||||
|
@ -1,13 +1,13 @@
|
||||
#![allow(unused_imports, unused_variables, dead_code)]
|
||||
use std::io::{self, Write};
|
||||
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bitflags::bitflags;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use http::header::{
|
||||
HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE,
|
||||
};
|
||||
use http::{Method, Version};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
|
||||
use super::{decoder, encoder};
|
||||
|
@ -2,11 +2,11 @@
|
||||
use std::fmt;
|
||||
use std::io::{self, Write};
|
||||
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bitflags::bitflags;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
|
||||
use http::{Method, StatusCode, Version};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
|
||||
use super::{decoder, encoder};
|
||||
@ -192,9 +192,9 @@ impl Encoder for Codec {
|
||||
mod tests {
|
||||
use std::{cmp, io};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use http::{Method, Version};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::*;
|
||||
use crate::error::ParseError;
|
||||
|
@ -1,13 +1,13 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{io, mem};
|
||||
|
||||
use actix_codec::Decoder;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::{Async, Poll};
|
||||
use http::header::{HeaderName, HeaderValue};
|
||||
use http::{header, HeaderMap, HttpTryFrom, Method, StatusCode, Uri, Version};
|
||||
use httparse;
|
||||
use log::{debug, error, trace};
|
||||
use tokio_codec::Decoder;
|
||||
|
||||
use crate::client::ClientResponse;
|
||||
use crate::error::ParseError;
|
||||
@ -607,9 +607,9 @@ impl ChunkedState {
|
||||
mod tests {
|
||||
use std::{cmp, io};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use http::{Method, Version};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::*;
|
||||
use crate::error::ParseError;
|
||||
|
@ -3,12 +3,11 @@ use std::fmt::Debug;
|
||||
use std::mem;
|
||||
use std::time::Instant;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::Service;
|
||||
use bitflags::bitflags;
|
||||
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
||||
use log::{debug, error, trace};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::Delay;
|
||||
|
||||
use crate::body::{Body, BodyLength, MessageBody, ResponseBody};
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! HTTP/1 implementation
|
||||
use std::fmt;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_codec::Framed;
|
||||
use bytes::Bytes;
|
||||
|
||||
mod client;
|
||||
|
@ -2,12 +2,11 @@ use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::net;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{IntoNewService, NewService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{IntoNewService, NewService, Service};
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::{try_ready, Async, Future, Poll, Stream};
|
||||
use log::error;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::MessageBody;
|
||||
use crate::config::{KeepAlive, ServiceConfig};
|
||||
|
@ -523,8 +523,8 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_rt::Runtime;
|
||||
use futures::future::{lazy, result};
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
|
||||
#[test]
|
||||
fn test_error() {
|
||||
|
@ -1,10 +1,9 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{NewService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{NewService, Service};
|
||||
use futures::future::{ok, Either, FutureResult};
|
||||
use futures::{Async, Future, Poll, Sink};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::{BodyLength, MessageBody, ResponseBody};
|
||||
use crate::error::{Error, ResponseError};
|
||||
|
16
src/test.rs
16
src/test.rs
@ -3,10 +3,10 @@ use std::str::FromStr;
|
||||
use std::sync::mpsc;
|
||||
use std::{net, thread};
|
||||
|
||||
use actix::System;
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::server::{Server, StreamServiceFactory};
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_rt::{Runtime, System};
|
||||
use actix_server::{Server, StreamServiceFactory};
|
||||
use actix_service::Service;
|
||||
|
||||
use bytes::Bytes;
|
||||
use cookie::Cookie;
|
||||
@ -14,8 +14,6 @@ use futures::future::{lazy, Future};
|
||||
use http::header::HeaderName;
|
||||
use http::{HeaderMap, HttpTryFrom, Method, Uri, Version};
|
||||
use net2::TcpBuilder;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::MessageBody;
|
||||
use crate::client::{
|
||||
@ -316,7 +314,7 @@ impl TestServer {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
|
||||
Server::default()
|
||||
Server::build()
|
||||
.listen("test", tcp, factory)
|
||||
.workers(1)
|
||||
.disable_signals()
|
||||
@ -390,9 +388,9 @@ impl<T> TestServerRuntime<T> {
|
||||
/// Construct test server url
|
||||
pub fn url(&self, uri: &str) -> String {
|
||||
if uri.starts_with('/') {
|
||||
format!("http://localhost:{}{}", self.addr.port(), uri)
|
||||
format!("http://127.0.0.1:{}{}", self.addr.port(), uri)
|
||||
} else {
|
||||
format!("http://localhost:{}/{}", self.addr.port(), uri)
|
||||
format!("http://127.0.0.1:{}/{}", self.addr.port(), uri)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Http client request
|
||||
use std::io;
|
||||
|
||||
use actix_net::connector::ConnectorError;
|
||||
use actix_connector::ConnectorError;
|
||||
use failure::Fail;
|
||||
use http::{header::HeaderValue, Error as HttpError, StatusCode};
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! websockets client
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
|
||||
use actix_service::Service;
|
||||
use base64;
|
||||
use futures::future::{err, Either, FutureResult};
|
||||
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
||||
@ -12,7 +12,6 @@ use http::{HttpTryFrom, StatusCode};
|
||||
use log::trace;
|
||||
use rand;
|
||||
use sha1::Sha1;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::BodyLength;
|
||||
use crate::client::ClientResponse;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::frame::Parser;
|
||||
use super::proto::{CloseReason, OpCode};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{NewService, Service};
|
||||
use actix_codec::Framed;
|
||||
use actix_service::{NewService, Service};
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::{Async, IntoFuture, Poll};
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::framed::{FramedTransport, FramedTransportError};
|
||||
use actix_net::service::{IntoService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{IntoService, Service};
|
||||
use actix_utils::framed::{FramedTransport, FramedTransportError};
|
||||
use futures::{Future, Poll};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::{Codec, Frame, Message};
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
extern crate actix;
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_service::NewService;
|
||||
use bytes::Bytes;
|
||||
use futures::future::{self, ok};
|
||||
|
||||
@ -35,6 +29,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||
|
||||
#[test]
|
||||
fn test_h1_v2() {
|
||||
env_logger::init();
|
||||
let mut srv = TestServer::with_factory(move || {
|
||||
h1::H1Service::build()
|
||||
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
|
||||
|
@ -1,14 +1,8 @@
|
||||
extern crate actix;
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use std::time::Duration;
|
||||
use std::{net, thread};
|
||||
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_service::NewService;
|
||||
use bytes::Bytes;
|
||||
use futures::future::{self, ok};
|
||||
use futures::stream::once;
|
||||
|
@ -1,16 +1,9 @@
|
||||
extern crate actix;
|
||||
extern crate actix_http;
|
||||
extern crate actix_net;
|
||||
extern crate actix_web;
|
||||
extern crate bytes;
|
||||
extern crate futures;
|
||||
|
||||
use std::io;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::framed::IntoFramed;
|
||||
use actix_net::service::NewServiceExt;
|
||||
use actix_net::stream::TakeItem;
|
||||
use actix_codec::Framed;
|
||||
use actix_service::NewService;
|
||||
use actix_utils::framed::IntoFramed;
|
||||
use actix_utils::stream::TakeItem;
|
||||
use actix_web::ws as web_ws;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::future::{lazy, ok, Either};
|
||||
@ -79,38 +72,6 @@ fn test_simple() {
|
||||
})
|
||||
});
|
||||
|
||||
{
|
||||
let url = srv.url("/");
|
||||
|
||||
let (reader, mut writer) = srv
|
||||
.block_on(lazy(|| web_ws::Client::new(url).connect()))
|
||||
.unwrap();
|
||||
|
||||
writer.text("text");
|
||||
let (item, reader) = srv.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(item, Some(web_ws::Message::Text("text".to_owned())));
|
||||
|
||||
writer.binary(b"text".as_ref());
|
||||
let (item, reader) = srv.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(
|
||||
item,
|
||||
Some(web_ws::Message::Binary(Bytes::from_static(b"text").into()))
|
||||
);
|
||||
|
||||
writer.ping("ping");
|
||||
let (item, reader) = srv.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(item, Some(web_ws::Message::Pong("ping".to_owned())));
|
||||
|
||||
writer.close(Some(web_ws::CloseCode::Normal.into()));
|
||||
let (item, _) = srv.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(
|
||||
item,
|
||||
Some(web_ws::Message::Close(Some(
|
||||
web_ws::CloseCode::Normal.into()
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
// client service
|
||||
let framed = srv.ws().unwrap();
|
||||
let framed = srv
|
||||
@ -142,5 +103,38 @@ fn test_simple() {
|
||||
assert_eq!(
|
||||
item,
|
||||
Some(ws::Frame::Close(Some(ws::CloseCode::Normal.into())))
|
||||
)
|
||||
);
|
||||
|
||||
{
|
||||
let mut sys = actix_web::actix::System::new("test");
|
||||
let url = srv.url("/");
|
||||
|
||||
let (reader, mut writer) = sys
|
||||
.block_on(lazy(|| web_ws::Client::new(url).connect()))
|
||||
.unwrap();
|
||||
|
||||
writer.text("text");
|
||||
let (item, reader) = sys.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(item, Some(web_ws::Message::Text("text".to_owned())));
|
||||
|
||||
writer.binary(b"text".as_ref());
|
||||
let (item, reader) = sys.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(
|
||||
item,
|
||||
Some(web_ws::Message::Binary(Bytes::from_static(b"text").into()))
|
||||
);
|
||||
|
||||
writer.ping("ping");
|
||||
let (item, reader) = sys.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(item, Some(web_ws::Message::Pong("ping".to_owned())));
|
||||
|
||||
writer.close(Some(web_ws::CloseCode::Normal.into()));
|
||||
let (item, _) = sys.block_on(reader.into_future()).unwrap();
|
||||
assert_eq!(
|
||||
item,
|
||||
Some(web_ws::Message::Close(Some(
|
||||
web_ws::CloseCode::Normal.into()
|
||||
)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user