diff --git a/Cargo.toml b/Cargo.toml index 57ed3f9b7..5afeda941 100644 --- a/Cargo.toml +++ b/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 } diff --git a/examples/echo.rs b/examples/echo.rs index 0453ad6a7..3bfb04d7c 100644 --- a/examples/echo.rs +++ b/examples/echo.rs @@ -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) diff --git a/examples/echo2.rs b/examples/echo2.rs index 3206ff507..0e2bc9d52 100644 --- a/examples/echo2.rs +++ b/examples/echo2.rs @@ -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 { @@ -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) diff --git a/examples/framed_hello.rs b/examples/framed_hello.rs index 6c53d27f3..5bbc3be9b 100644 --- a/examples/framed_hello.rs +++ b/examples/framed_hello.rs @@ -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(|_| ())) diff --git a/examples/hello-world.rs b/examples/hello-world.rs index b477f191d..e0c322a22 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -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) diff --git a/src/client/connect.rs b/src/client/connect.rs index a445228e3..f4112cfaa 100644 --- a/src/client/connect.rs +++ b/src/client/connect.rs @@ -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}; diff --git a/src/client/connection.rs b/src/client/connection.rs index 363a4ece9..ed156bf84 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -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; diff --git a/src/client/connector.rs b/src/client/connector.rs index 74ee6a7e3..fdc996ffe 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -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 { diff --git a/src/client/error.rs b/src/client/error.rs index d2a0f38ec..815bc1edc 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -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 for ConnectorError { } } +#[cfg(feature = "ssl")] +impl From for ConnectorError { + fn from(err: SslError) -> ConnectorError { + ConnectorError::SslError(err) + } +} + +#[cfg(feature = "ssl")] +impl From> for ConnectorError { + fn from(err: HandshakeError) -> 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 { diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index fc1e53e8f..8d946d644 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -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; diff --git a/src/client/pool.rs b/src/client/pool.rs index decf80194..94e96899e 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -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; diff --git a/src/client/request.rs b/src/client/request.rs index 5f294bbd8..fbb1e840b 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -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 -/// .header("User-Agent", "Actix-web") -/// .finish().unwrap() -/// .send() // <- Send http request -/// .map_err(|_| ()) -/// .and_then(|response| { // <- server http response -/// println!("Response: {:?}", response); -/// # actix::System::current().stop(); -/// Ok(()) -/// }), -/// ); +/// 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(&mut connector) // <- Send http request +/// .map_err(|_| ()) +/// .and_then(|response| { // <- server http response +/// println!("Response: {:?}", response); +/// # actix_rt::System::current().stop(); +/// Ok(()) +/// }) +/// })); /// } /// ``` pub struct ClientRequest { diff --git a/src/config.rs b/src/config.rs index 661c0901f..67c928fb7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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); diff --git a/src/error.rs b/src/error.rs index 280f9a329..49602bd98 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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)] diff --git a/src/h1/client.rs b/src/h1/client.rs index f547983fa..de4d10e1b 100644 --- a/src/h1/client.rs +++ b/src/h1/client.rs @@ -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}; diff --git a/src/h1/codec.rs b/src/h1/codec.rs index d67d36085..fbc8b4a58 100644 --- a/src/h1/codec.rs +++ b/src/h1/codec.rs @@ -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; diff --git a/src/h1/decoder.rs b/src/h1/decoder.rs index e5971f750..460d2b3aa 100644 --- a/src/h1/decoder.rs +++ b/src/h1/decoder.rs @@ -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; diff --git a/src/h1/dispatcher.rs b/src/h1/dispatcher.rs index 59b419c3e..569b1deeb 100644 --- a/src/h1/dispatcher.rs +++ b/src/h1/dispatcher.rs @@ -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}; diff --git a/src/h1/mod.rs b/src/h1/mod.rs index 461ecb959..a375b60d3 100644 --- a/src/h1/mod.rs +++ b/src/h1/mod.rs @@ -1,7 +1,7 @@ //! HTTP/1 implementation use std::fmt; -use actix_net::codec::Framed; +use actix_codec::Framed; use bytes::Bytes; mod client; diff --git a/src/h1/service.rs b/src/h1/service.rs index 1a5a587c0..7c2589cc8 100644 --- a/src/h1/service.rs +++ b/src/h1/service.rs @@ -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}; diff --git a/src/payload.rs b/src/payload.rs index 37f06d433..ea266f70b 100644 --- a/src/payload.rs +++ b/src/payload.rs @@ -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() { diff --git a/src/service.rs b/src/service.rs index a6a820977..f98234e76 100644 --- a/src/service.rs +++ b/src/service.rs @@ -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}; diff --git a/src/test.rs b/src/test.rs index 308d2b4df..c264ac47a 100644 --- a/src/test.rs +++ b/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 TestServerRuntime { /// 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) } } diff --git a/src/ws/client/error.rs b/src/ws/client/error.rs index 62a3f47a9..02c723755 100644 --- a/src/ws/client/error.rs +++ b/src/ws/client/error.rs @@ -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}; diff --git a/src/ws/client/service.rs b/src/ws/client/service.rs index 8dd407b0e..c48b6e0c1 100644 --- a/src/ws/client/service.rs +++ b/src/ws/client/service.rs @@ -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; diff --git a/src/ws/codec.rs b/src/ws/codec.rs index 10c505287..286d15f8c 100644 --- a/src/ws/codec.rs +++ b/src/ws/codec.rs @@ -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}; diff --git a/src/ws/service.rs b/src/ws/service.rs index 846278147..8189b1955 100644 --- a/src/ws/service.rs +++ b/src/ws/service.rs @@ -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}; diff --git a/src/ws/transport.rs b/src/ws/transport.rs index 8cd79cb03..f59ad67a7 100644 --- a/src/ws/transport.rs +++ b/src/ws/transport.rs @@ -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}; diff --git a/tests/test_client.rs b/tests/test_client.rs index 3e14cd7b7..f19edda13 100644 --- a/tests/test_client.rs +++ b/tests/test_client.rs @@ -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))) diff --git a/tests/test_server.rs b/tests/test_server.rs index d169e5a98..cb9cd3f9d 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -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; diff --git a/tests/test_ws.rs b/tests/test_ws.rs index f890c586e..11a3f472b 100644 --- a/tests/test_ws.rs +++ b/tests/test_ws.rs @@ -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() + ))) + ); + } }