1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 16:02:59 +01:00

use new actix crates

This commit is contained in:
Nikolay Kim 2018-12-10 18:08:33 -08:00
parent 9f4d48f7a1
commit aaae368ed9
31 changed files with 174 additions and 227 deletions

View File

@ -28,61 +28,55 @@ name = "actix_http"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
default = ["session", "cell"] default = ["session"]
# sessions feature, session require "ring" crate and c compiler # sessions feature, session require "ring" crate and c compiler
session = ["cookie/secure"] session = ["cookie/secure"]
cell = ["actix-net/cell"]
# tls
tls = ["native-tls", "actix-net/tls"]
# openssl # openssl
ssl = ["openssl", "actix-net/ssl"] ssl = ["openssl", "actix-connector/ssl"]
# rustls
rust-tls = ["rustls", "actix-net/rust-tls"]
[dependencies] [dependencies]
actix = "0.7.5" actix-service = "0.1.1"
#actix-net = "0.3.0" actix-codec = { git="https://github.com/actix/actix-net.git" }
actix-net = { 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" base64 = "0.9"
bitflags = "1.0" 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" http = "0.1.8"
httparse = "1.3" httparse = "1.3"
failure = "0.1.3"
indexmap = "1.0" indexmap = "1.0"
log = "0.4" log = "0.4"
mime = "0.3" mime = "0.3"
net2 = "0.2"
percent-encoding = "1.0"
rand = "0.5" rand = "0.5"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"
sha1 = "0.6" 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" slab = "0.4"
bytes = "0.4" serde_urlencoded = "0.5.3"
byteorder = "1.2" time = "0.1"
futures = "0.1"
tokio-codec = "0.1"
tokio = "0.1"
tokio-io = "0.1"
tokio-tcp = "0.1" tokio-tcp = "0.1"
tokio-timer = "0.2" tokio-timer = "0.2"
tokio-current-thread = "0.1"
trust-dns-proto = "0.5.0" trust-dns-proto = "0.5.0"
trust-dns-resolver = "0.10.0" trust-dns-resolver = "0.10.0"
url = { version="1.7", features=["query_encoding"] }
# native-tls # native-tls
native-tls = { version="0.2", optional = true } native-tls = { version="0.2", optional = true }

View File

@ -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::HttpMessage;
use actix_http::{h1, Request, Response}; use actix_http::{h1, Request, Response};
use actix_net::server::Server; use actix_server::Server;
use actix_net::service::NewServiceExt; use actix_service::NewService;
use bytes::Bytes; use bytes::Bytes;
use futures::Future; use futures::Future;
use http::header::HeaderValue; use http::header::HeaderValue;
use log::info;
use std::env; use std::env;
fn main() { fn main() {
env::set_var("RUST_LOG", "echo=info"); env::set_var("RUST_LOG", "echo=info");
env_logger::init(); env_logger::init();
Server::new() Server::build()
.bind("echo", "127.0.0.1:8080", || { .bind("echo", "127.0.0.1:8080", || {
h1::H1Service::build() h1::H1Service::build()
.client_timeout(1000) .client_timeout(1000)

View File

@ -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::http::HeaderValue;
use actix_http::HttpMessage; use actix_http::HttpMessage;
use actix_http::{h1, Error, Request, Response}; use actix_http::{h1, Error, Request, Response};
use actix_net::server::Server; use actix_server::Server;
use actix_net::service::NewServiceExt; use actix_service::NewService;
use bytes::Bytes; use bytes::Bytes;
use futures::Future; use futures::Future;
use log::info;
use std::env; use std::env;
fn handle_request(_req: Request) -> impl Future<Item = Response, Error = Error> { 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::set_var("RUST_LOG", "echo=info");
env_logger::init(); env_logger::init();
Server::new() Server::build()
.bind("echo", "127.0.0.1:8080", || { .bind("echo", "127.0.0.1:8080", || {
h1::H1Service::build() h1::H1Service::build()
.client_timeout(1000) .client_timeout(1000)

View File

@ -1,18 +1,9 @@
extern crate env_logger; use actix_codec::Framed;
extern crate log;
extern crate actix_http;
extern crate actix_net;
extern crate bytes;
extern crate futures;
extern crate http;
use actix_http::{h1, Response, SendResponse, ServiceConfig}; use actix_http::{h1, Response, SendResponse, ServiceConfig};
use actix_net::codec::Framed; use actix_server::Server;
use actix_net::framed::IntoFramed; use actix_service::NewService;
use actix_net::server::Server; use actix_utils::framed::IntoFramed;
use actix_net::service::NewServiceExt; use actix_utils::stream::TakeItem;
use actix_net::stream::TakeItem;
use futures::Future; use futures::Future;
use std::env; use std::env;
@ -20,7 +11,7 @@ fn main() {
env::set_var("RUST_LOG", "framed_hello=info"); env::set_var("RUST_LOG", "framed_hello=info");
env_logger::init(); env_logger::init();
Server::new() Server::build()
.bind("framed_hello", "127.0.0.1:8080", || { .bind("framed_hello", "127.0.0.1:8080", || {
IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) IntoFramed::new(|| h1::Codec::new(ServiceConfig::default()))
.and_then(TakeItem::new().map_err(|_| ())) .and_then(TakeItem::new().map_err(|_| ()))

View File

@ -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_http::{h1, Response};
use actix_net::server::Server; use actix_server::Server;
use actix_net::service::NewServiceExt; use actix_service::NewService;
use futures::future; use futures::future;
use http::header::HeaderValue; use http::header::HeaderValue;
use log::info;
use std::env; use std::env;
fn main() { fn main() {
env::set_var("RUST_LOG", "hello_world=info"); env::set_var("RUST_LOG", "hello_world=info");
env_logger::init(); env_logger::init();
Server::new() Server::build()
.bind("hello-world", "127.0.0.1:8080", || { .bind("hello-world", "127.0.0.1:8080", || {
h1::H1Service::build() h1::H1Service::build()
.client_timeout(1000) .client_timeout(1000)

View File

@ -1,5 +1,4 @@
use actix_net::connector::RequestPort; use actix_connector::{RequestHost, RequestPort};
use actix_net::resolver::RequestHost;
use http::uri::Uri; use http::uri::Uri;
use http::{Error as HttpError, HttpTryFrom}; use http::{Error as HttpError, HttpTryFrom};

View File

@ -1,7 +1,7 @@
use std::{fmt, io, time}; use std::{fmt, io, time};
use actix_codec::{AsyncRead, AsyncWrite};
use futures::Poll; use futures::Poll;
use tokio_io::{AsyncRead, AsyncWrite};
use super::pool::Acquired; use super::pool::Acquired;

View File

@ -1,13 +1,12 @@
use std::time::Duration; use std::time::Duration;
use std::{fmt, io}; use std::{fmt, io};
use actix_net::connector::TcpConnector; use actix_codec::{AsyncRead, AsyncWrite};
use actix_net::resolver::Resolver; use actix_connector::{Resolver, TcpConnector};
use actix_net::service::{Service, ServiceExt}; use actix_service::Service;
use actix_net::timeout::{TimeoutError, TimeoutService}; use actix_utils::timeout::{TimeoutError, TimeoutService};
use futures::future::Either; use futures::future::Either;
use futures::Poll; use futures::Poll;
use tokio_io::{AsyncRead, AsyncWrite};
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use super::connect::Connect; use super::connect::Connect;
@ -16,7 +15,7 @@ use super::error::ConnectorError;
use super::pool::ConnectionPool; use super::pool::ConnectionPool;
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
use actix_net::ssl::OpensslConnector; use actix_connector::ssl::OpensslConnector;
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
use openssl::ssl::{SslConnector, SslMethod}; use openssl::ssl::{SslConnector, SslMethod};
@ -169,7 +168,7 @@ impl Connector {
.and_then(TcpConnector::default().from_err()) .and_then(TcpConnector::default().from_err())
.and_then( .and_then(
OpensslConnector::service(self.connector) OpensslConnector::service(self.connector)
.map_err(ConnectorError::SslError), .map_err(ConnectorError::from),
), ),
) )
.map_err(|e| match e { .map_err(|e| match e {

View File

@ -4,13 +4,7 @@ use failure::Fail;
use trust_dns_resolver::error::ResolveError; use trust_dns_resolver::error::ResolveError;
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
use openssl::ssl::Error as SslError; use openssl::ssl::{Error as SslError, HandshakeError};
#[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 crate::error::{Error, ParseError}; use crate::error::{Error, ParseError};
@ -26,7 +20,7 @@ pub enum ConnectorError {
SslIsNotSupported, SslIsNotSupported,
/// SSL error /// SSL error
#[cfg(any(feature = "tls", feature = "ssl", feature = "rust-tls"))] #[cfg(feature = "ssl")]
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
SslError(#[cause] SslError), 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 /// A set of errors that can occur during request sending and response reading
#[derive(Debug)] #[derive(Debug)]
pub enum SendRequestError { pub enum SendRequestError {

View File

@ -1,11 +1,10 @@
use std::collections::VecDeque; use std::collections::VecDeque;
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::service::Service; use actix_service::Service;
use bytes::Bytes; use bytes::Bytes;
use futures::future::{err, ok, Either}; use futures::future::{err, ok, Either};
use futures::{Async, Future, Poll, Sink, Stream}; use futures::{Async, Future, Poll, Sink, Stream};
use tokio_io::{AsyncRead, AsyncWrite};
use super::error::{ConnectorError, SendRequestError}; use super::error::{ConnectorError, SendRequestError};
use super::response::ClientResponse; use super::response::ClientResponse;

View File

@ -4,7 +4,9 @@ use std::io;
use std::rc::Rc; use std::rc::Rc;
use std::time::{Duration, Instant}; 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::future::{ok, Either, FutureResult};
use futures::sync::oneshot; use futures::sync::oneshot;
use futures::task::AtomicTask; use futures::task::AtomicTask;
@ -12,8 +14,6 @@ use futures::{Async, Future, Poll};
use http::uri::Authority; use http::uri::Authority;
use indexmap::IndexSet; use indexmap::IndexSet;
use slab::Slab; use slab::Slab;
use tokio_current_thread::spawn;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_timer::{sleep, Delay}; use tokio_timer::{sleep, Delay};
use super::connect::Connect; use super::connect::Connect;

View File

@ -2,7 +2,7 @@ use std::fmt;
use std::fmt::Write as FmtWrite; use std::fmt::Write as FmtWrite;
use std::io::Write; use std::io::Write;
use actix_net::service::Service; use actix_service::Service;
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use cookie::{Cookie, CookieJar}; use cookie::{Cookie, CookieJar};
use futures::{Future, Stream}; use futures::{Future, Stream};
@ -23,26 +23,24 @@ use super::{pipeline, Connect, Connection, ConnectorError, SendRequestError};
/// An HTTP Client Request /// An HTTP Client Request
/// ///
/// ```rust /// ```rust
/// # extern crate actix_web; /// use futures::future::{Future, lazy};
/// # extern crate futures; /// use actix_rt::System;
/// # extern crate tokio; /// use actix_http::client;
/// # use futures::Future;
/// # use std::process;
/// use actix_web::{actix, client};
/// ///
/// fn main() { /// fn main() {
/// actix::run( /// System::new("test").block_on(lazy(|| {
/// || client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder /// let mut connector = client::Connector::default().service();
/// .header("User-Agent", "Actix-web") /// client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
/// .finish().unwrap() /// .header("User-Agent", "Actix-web")
/// .send() // <- Send http request /// .finish().unwrap()
/// .map_err(|_| ()) /// .send(&mut connector) // <- Send http request
/// .and_then(|response| { // <- server http response /// .map_err(|_| ())
/// println!("Response: {:?}", response); /// .and_then(|response| { // <- server http response
/// # actix::System::current().stop(); /// println!("Response: {:?}", response);
/// Ok(()) /// # actix_rt::System::current().stop();
/// }), /// Ok(())
/// ); /// })
/// }));
/// } /// }
/// ``` /// ```
pub struct ClientRequest<B: MessageBody = ()> { pub struct ClientRequest<B: MessageBody = ()> {

View File

@ -4,11 +4,11 @@ use std::rc::Rc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use std::{fmt, net}; use std::{fmt, net};
use actix_rt::spawn;
use bytes::BytesMut; use bytes::BytesMut;
use futures::{future, Future}; use futures::{future, Future};
use log::error; use log::error;
use time; use time;
use tokio_current_thread::spawn;
use tokio_timer::{sleep, Delay}; use tokio_timer::{sleep, Delay};
// "Sun, 06 Nov 1994 08:49:37 GMT".len() // "Sun, 06 Nov 1994 08:49:37 GMT".len()
@ -378,8 +378,8 @@ impl DateService {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use actix_rt::System;
use futures::future; use futures::future;
use tokio::runtime::current_thread;
#[test] #[test]
fn test_date_len() { fn test_date_len() {
@ -388,7 +388,7 @@ mod tests {
#[test] #[test]
fn test_date() { fn test_date() {
let mut rt = current_thread::Runtime::new().unwrap(); let mut rt = System::new("test");
let _ = rt.block_on(future::lazy(|| { let _ = rt.block_on(future::lazy(|| {
let settings = ServiceConfig::new(KeepAlive::Os, 0, 0); let settings = ServiceConfig::new(KeepAlive::Os, 0, 0);

View File

@ -5,7 +5,7 @@ use std::string::FromUtf8Error;
use std::sync::Mutex; use std::sync::Mutex;
use std::{fmt, io, result}; use std::{fmt, io, result};
use actix::MailboxError; // use actix::MailboxError;
use cookie; use cookie;
use failure::{self, Backtrace, Fail}; use failure::{self, Backtrace, Fail};
use futures::Canceled; use futures::Canceled;
@ -250,8 +250,8 @@ impl ResponseError for header::InvalidHeaderValueBytes {
/// `InternalServerError` for `futures::Canceled` /// `InternalServerError` for `futures::Canceled`
impl ResponseError for Canceled {} impl ResponseError for Canceled {}
/// `InternalServerError` for `actix::MailboxError` // /// `InternalServerError` for `actix::MailboxError`
impl ResponseError for MailboxError {} // impl ResponseError for MailboxError {}
/// A set of errors that can occur during parsing HTTP streams /// A set of errors that can occur during parsing HTTP streams
#[derive(Fail, Debug)] #[derive(Fail, Debug)]

View File

@ -1,13 +1,13 @@
#![allow(unused_imports, unused_variables, dead_code)] #![allow(unused_imports, unused_variables, dead_code)]
use std::io::{self, Write}; use std::io::{self, Write};
use actix_codec::{Decoder, Encoder};
use bitflags::bitflags; use bitflags::bitflags;
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use http::header::{ use http::header::{
HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE, HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE,
}; };
use http::{Method, Version}; use http::{Method, Version};
use tokio_codec::{Decoder, Encoder};
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType}; use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
use super::{decoder, encoder}; use super::{decoder, encoder};

View File

@ -2,11 +2,11 @@
use std::fmt; use std::fmt;
use std::io::{self, Write}; use std::io::{self, Write};
use actix_codec::{Decoder, Encoder};
use bitflags::bitflags; use bitflags::bitflags;
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING}; use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
use http::{Method, StatusCode, Version}; use http::{Method, StatusCode, Version};
use tokio_codec::{Decoder, Encoder};
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType}; use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
use super::{decoder, encoder}; use super::{decoder, encoder};
@ -192,9 +192,9 @@ impl Encoder for Codec {
mod tests { mod tests {
use std::{cmp, io}; use std::{cmp, io};
use actix_codec::{AsyncRead, AsyncWrite};
use bytes::{Buf, Bytes, BytesMut}; use bytes::{Buf, Bytes, BytesMut};
use http::{Method, Version}; use http::{Method, Version};
use tokio_io::{AsyncRead, AsyncWrite};
use super::*; use super::*;
use crate::error::ParseError; use crate::error::ParseError;

View File

@ -1,13 +1,13 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::{io, mem}; use std::{io, mem};
use actix_codec::Decoder;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures::{Async, Poll}; use futures::{Async, Poll};
use http::header::{HeaderName, HeaderValue}; use http::header::{HeaderName, HeaderValue};
use http::{header, HeaderMap, HttpTryFrom, Method, StatusCode, Uri, Version}; use http::{header, HeaderMap, HttpTryFrom, Method, StatusCode, Uri, Version};
use httparse; use httparse;
use log::{debug, error, trace}; use log::{debug, error, trace};
use tokio_codec::Decoder;
use crate::client::ClientResponse; use crate::client::ClientResponse;
use crate::error::ParseError; use crate::error::ParseError;
@ -607,9 +607,9 @@ impl ChunkedState {
mod tests { mod tests {
use std::{cmp, io}; use std::{cmp, io};
use actix_codec::{AsyncRead, AsyncWrite};
use bytes::{Buf, Bytes, BytesMut}; use bytes::{Buf, Bytes, BytesMut};
use http::{Method, Version}; use http::{Method, Version};
use tokio_io::{AsyncRead, AsyncWrite};
use super::*; use super::*;
use crate::error::ParseError; use crate::error::ParseError;

View File

@ -3,12 +3,11 @@ use std::fmt::Debug;
use std::mem; use std::mem;
use std::time::Instant; use std::time::Instant;
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::service::Service; use actix_service::Service;
use bitflags::bitflags; use bitflags::bitflags;
use futures::{try_ready, Async, Future, Poll, Sink, Stream}; use futures::{try_ready, Async, Future, Poll, Sink, Stream};
use log::{debug, error, trace}; use log::{debug, error, trace};
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_timer::Delay; use tokio_timer::Delay;
use crate::body::{Body, BodyLength, MessageBody, ResponseBody}; use crate::body::{Body, BodyLength, MessageBody, ResponseBody};

View File

@ -1,7 +1,7 @@
//! HTTP/1 implementation //! HTTP/1 implementation
use std::fmt; use std::fmt;
use actix_net::codec::Framed; use actix_codec::Framed;
use bytes::Bytes; use bytes::Bytes;
mod client; mod client;

View File

@ -2,12 +2,11 @@ use std::fmt::Debug;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::net; use std::net;
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::service::{IntoNewService, NewService, Service}; use actix_service::{IntoNewService, NewService, Service};
use futures::future::{ok, FutureResult}; use futures::future::{ok, FutureResult};
use futures::{try_ready, Async, Future, Poll, Stream}; use futures::{try_ready, Async, Future, Poll, Stream};
use log::error; use log::error;
use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::MessageBody; use crate::body::MessageBody;
use crate::config::{KeepAlive, ServiceConfig}; use crate::config::{KeepAlive, ServiceConfig};

View File

@ -523,8 +523,8 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use actix_rt::Runtime;
use futures::future::{lazy, result}; use futures::future::{lazy, result};
use tokio::runtime::current_thread::Runtime;
#[test] #[test]
fn test_error() { fn test_error() {

View File

@ -1,10 +1,9 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::service::{NewService, Service}; use actix_service::{NewService, Service};
use futures::future::{ok, Either, FutureResult}; use futures::future::{ok, Either, FutureResult};
use futures::{Async, Future, Poll, Sink}; use futures::{Async, Future, Poll, Sink};
use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::{BodyLength, MessageBody, ResponseBody}; use crate::body::{BodyLength, MessageBody, ResponseBody};
use crate::error::{Error, ResponseError}; use crate::error::{Error, ResponseError};

View File

@ -3,10 +3,10 @@ use std::str::FromStr;
use std::sync::mpsc; use std::sync::mpsc;
use std::{net, thread}; use std::{net, thread};
use actix::System; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::codec::Framed; use actix_rt::{Runtime, System};
use actix_net::server::{Server, StreamServiceFactory}; use actix_server::{Server, StreamServiceFactory};
use actix_net::service::Service; use actix_service::Service;
use bytes::Bytes; use bytes::Bytes;
use cookie::Cookie; use cookie::Cookie;
@ -14,8 +14,6 @@ use futures::future::{lazy, Future};
use http::header::HeaderName; use http::header::HeaderName;
use http::{HeaderMap, HttpTryFrom, Method, Uri, Version}; use http::{HeaderMap, HttpTryFrom, Method, Uri, Version};
use net2::TcpBuilder; use net2::TcpBuilder;
use tokio::runtime::current_thread::Runtime;
use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::MessageBody; use crate::body::MessageBody;
use crate::client::{ use crate::client::{
@ -316,7 +314,7 @@ impl TestServer {
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap(); let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
let local_addr = tcp.local_addr().unwrap(); let local_addr = tcp.local_addr().unwrap();
Server::default() Server::build()
.listen("test", tcp, factory) .listen("test", tcp, factory)
.workers(1) .workers(1)
.disable_signals() .disable_signals()
@ -390,9 +388,9 @@ impl<T> TestServerRuntime<T> {
/// Construct test server url /// Construct test server url
pub fn url(&self, uri: &str) -> String { pub fn url(&self, uri: &str) -> String {
if uri.starts_with('/') { if uri.starts_with('/') {
format!("http://localhost:{}{}", self.addr.port(), uri) format!("http://127.0.0.1:{}{}", self.addr.port(), uri)
} else { } else {
format!("http://localhost:{}/{}", self.addr.port(), uri) format!("http://127.0.0.1:{}/{}", self.addr.port(), uri)
} }
} }

View File

@ -1,7 +1,7 @@
//! Http client request //! Http client request
use std::io; use std::io;
use actix_net::connector::ConnectorError; use actix_connector::ConnectorError;
use failure::Fail; use failure::Fail;
use http::{header::HeaderValue, Error as HttpError, StatusCode}; use http::{header::HeaderValue, Error as HttpError, StatusCode};

View File

@ -1,9 +1,9 @@
//! websockets client //! websockets client
use std::marker::PhantomData; use std::marker::PhantomData;
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::connector::{Connect as TcpConnect, ConnectorError, DefaultConnector}; use actix_connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
use actix_net::service::Service; use actix_service::Service;
use base64; use base64;
use futures::future::{err, Either, FutureResult}; use futures::future::{err, Either, FutureResult};
use futures::{try_ready, Async, Future, Poll, Sink, Stream}; use futures::{try_ready, Async, Future, Poll, Sink, Stream};
@ -12,7 +12,6 @@ use http::{HttpTryFrom, StatusCode};
use log::trace; use log::trace;
use rand; use rand;
use sha1::Sha1; use sha1::Sha1;
use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::BodyLength; use crate::body::BodyLength;
use crate::client::ClientResponse; use crate::client::ClientResponse;

View File

@ -1,5 +1,5 @@
use actix_codec::{Decoder, Encoder};
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use tokio_codec::{Decoder, Encoder};
use super::frame::Parser; use super::frame::Parser;
use super::proto::{CloseReason, OpCode}; use super::proto::{CloseReason, OpCode};

View File

@ -1,7 +1,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use actix_net::codec::Framed; use actix_codec::Framed;
use actix_net::service::{NewService, Service}; use actix_service::{NewService, Service};
use futures::future::{ok, FutureResult}; use futures::future::{ok, FutureResult};
use futures::{Async, IntoFuture, Poll}; use futures::{Async, IntoFuture, Poll};

View File

@ -1,8 +1,7 @@
use actix_net::codec::Framed; use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_net::framed::{FramedTransport, FramedTransportError}; use actix_service::{IntoService, Service};
use actix_net::service::{IntoService, Service}; use actix_utils::framed::{FramedTransport, FramedTransportError};
use futures::{Future, Poll}; use futures::{Future, Poll};
use tokio_io::{AsyncRead, AsyncWrite};
use super::{Codec, Frame, Message}; use super::{Codec, Frame, Message};

View File

@ -1,10 +1,4 @@
extern crate actix; use actix_service::NewService;
extern crate actix_http;
extern crate actix_net;
extern crate bytes;
extern crate futures;
use actix_net::service::NewServiceExt;
use bytes::Bytes; use bytes::Bytes;
use futures::future::{self, ok}; use futures::future::{self, ok};
@ -35,6 +29,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
#[test] #[test]
fn test_h1_v2() { fn test_h1_v2() {
env_logger::init();
let mut srv = TestServer::with_factory(move || { let mut srv = TestServer::with_factory(move || {
h1::H1Service::build() h1::H1Service::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR))) .finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))

View File

@ -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::io::{Read, Write};
use std::time::Duration; use std::time::Duration;
use std::{net, thread}; use std::{net, thread};
use actix_net::service::NewServiceExt; use actix_service::NewService;
use bytes::Bytes; use bytes::Bytes;
use futures::future::{self, ok}; use futures::future::{self, ok};
use futures::stream::once; use futures::stream::once;

View File

@ -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 std::io;
use actix_net::codec::Framed; use actix_codec::Framed;
use actix_net::framed::IntoFramed; use actix_service::NewService;
use actix_net::service::NewServiceExt; use actix_utils::framed::IntoFramed;
use actix_net::stream::TakeItem; use actix_utils::stream::TakeItem;
use actix_web::ws as web_ws; use actix_web::ws as web_ws;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use futures::future::{lazy, ok, Either}; 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 // client service
let framed = srv.ws().unwrap(); let framed = srv.ws().unwrap();
let framed = srv let framed = srv
@ -142,5 +103,38 @@ fn test_simple() {
assert_eq!( assert_eq!(
item, item,
Some(ws::Frame::Close(Some(ws::CloseCode::Normal.into()))) 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()
)))
);
}
} }