diff --git a/actix-http/.gitignore b/actix-http/.gitignore deleted file mode 100644 index 42d0755dd..000000000 --- a/actix-http/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -Cargo.lock -target/ -guide/build/ -/gh-pages - -*.so -*.out -*.pyc -*.pid -*.sock -*~ - -# These are backup files generated by rustfmt -**/*.rs.bk diff --git a/actix-http/.travis.yml b/actix-http/.travis.yml deleted file mode 100644 index 02fbd42c7..000000000 --- a/actix-http/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -language: rust -sudo: required -dist: trusty - -cache: - cargo: true - apt: true - -matrix: - include: - - rust: stable - - rust: beta - - rust: nightly-2019-03-02 - allow_failures: - - rust: nightly-2019-03-02 - -env: - global: - - RUSTFLAGS="-C link-dead-code" - - OPENSSL_VERSION=openssl-1.0.2 - -before_install: - - sudo add-apt-repository -y ppa:0k53d-karl-f830m/openssl - - sudo apt-get update -qq - - sudo apt-get install -y openssl libssl-dev libelf-dev libdw-dev cmake gcc binutils-dev libiberty-dev - -before_cache: | - if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-03-02" ]]; then - RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install cargo-tarpaulin - fi - -script: -- cargo clean -- cargo build --all-features -- cargo test --all-features - -# Upload docs -after_success: - - | - if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then - cargo doc --no-deps && - echo "" > target/doc/index.html && - git clone https://github.com/davisp/ghp-import.git && - ./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc && - echo "Uploaded documentation" - fi - - | - if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-03-02" ]]; then - taskset -c 0 cargo tarpaulin --features="ssl" --out Xml - bash <(curl -s https://codecov.io/bash) - echo "Uploaded code coverage" - fi diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 427024e24..99d80b0be 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -12,7 +12,6 @@ categories = ["network-programming", "asynchronous", "web-programming::http-server", "web-programming::websocket"] license = "MIT/Apache-2.0" -exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] edition = "2018" workspace = ".." diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index e1399e6b4..85717ba85 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -7,8 +7,8 @@ use futures::{Async, Poll, Stream}; use crate::error::Error; #[derive(Debug, PartialEq, Copy, Clone)] -/// Different type of body -pub enum BodyLength { +/// Body size hint +pub enum BodySize { None, Empty, Sized(usize), @@ -16,13 +16,13 @@ pub enum BodyLength { Stream, } -impl BodyLength { +impl BodySize { pub fn is_eof(&self) -> bool { match self { - BodyLength::None - | BodyLength::Empty - | BodyLength::Sized(0) - | BodyLength::Sized64(0) => true, + BodySize::None + | BodySize::Empty + | BodySize::Sized(0) + | BodySize::Sized64(0) => true, _ => false, } } @@ -30,14 +30,14 @@ impl BodyLength { /// Type that provides this trait can be streamed to a peer. pub trait MessageBody { - fn length(&self) -> BodyLength; + fn length(&self) -> BodySize; fn poll_next(&mut self) -> Poll, Error>; } impl MessageBody for () { - fn length(&self) -> BodyLength { - BodyLength::Empty + fn length(&self) -> BodySize { + BodySize::Empty } fn poll_next(&mut self) -> Poll, Error> { @@ -46,7 +46,7 @@ impl MessageBody for () { } impl MessageBody for Box { - fn length(&self) -> BodyLength { + fn length(&self) -> BodySize { self.as_ref().length() } @@ -86,7 +86,7 @@ impl ResponseBody { } impl MessageBody for ResponseBody { - fn length(&self) -> BodyLength { + fn length(&self) -> BodySize { match self { ResponseBody::Body(ref body) => body.length(), ResponseBody::Other(ref body) => body.length(), @@ -135,11 +135,11 @@ impl Body { } impl MessageBody for Body { - fn length(&self) -> BodyLength { + fn length(&self) -> BodySize { match self { - Body::None => BodyLength::None, - Body::Empty => BodyLength::Empty, - Body::Bytes(ref bin) => BodyLength::Sized(bin.len()), + Body::None => BodySize::None, + Body::Empty => BodySize::Empty, + Body::Bytes(ref bin) => BodySize::Sized(bin.len()), Body::Message(ref body) => body.length(), } } @@ -235,8 +235,8 @@ impl From for Body { } impl MessageBody for Bytes { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -249,8 +249,8 @@ impl MessageBody for Bytes { } impl MessageBody for BytesMut { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -265,8 +265,8 @@ impl MessageBody for BytesMut { } impl MessageBody for &'static str { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -281,8 +281,8 @@ impl MessageBody for &'static str { } impl MessageBody for &'static [u8] { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -297,8 +297,8 @@ impl MessageBody for &'static [u8] { } impl MessageBody for Vec { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -314,8 +314,8 @@ impl MessageBody for Vec { } impl MessageBody for String { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.len()) + fn length(&self) -> BodySize { + BodySize::Sized(self.len()) } fn poll_next(&mut self) -> Poll, Error> { @@ -354,8 +354,8 @@ where S: Stream, E: Into, { - fn length(&self) -> BodyLength { - BodyLength::Stream + fn length(&self) -> BodySize { + BodySize::Stream } fn poll_next(&mut self) -> Poll, Error> { @@ -383,8 +383,8 @@ impl MessageBody for SizedStream where S: Stream, { - fn length(&self) -> BodyLength { - BodyLength::Sized(self.size) + fn length(&self) -> BodySize { + BodySize::Sized(self.size) } fn poll_next(&mut self) -> Poll, Error> { @@ -416,50 +416,47 @@ mod tests { #[test] fn test_static_str() { - assert_eq!(Body::from("").length(), BodyLength::Sized(0)); - assert_eq!(Body::from("test").length(), BodyLength::Sized(4)); + assert_eq!(Body::from("").length(), BodySize::Sized(0)); + assert_eq!(Body::from("test").length(), BodySize::Sized(4)); assert_eq!(Body::from("test").get_ref(), b"test"); } #[test] fn test_static_bytes() { - assert_eq!(Body::from(b"test".as_ref()).length(), BodyLength::Sized(4)); + assert_eq!(Body::from(b"test".as_ref()).length(), BodySize::Sized(4)); assert_eq!(Body::from(b"test".as_ref()).get_ref(), b"test"); assert_eq!( Body::from_slice(b"test".as_ref()).length(), - BodyLength::Sized(4) + BodySize::Sized(4) ); assert_eq!(Body::from_slice(b"test".as_ref()).get_ref(), b"test"); } #[test] fn test_vec() { - assert_eq!(Body::from(Vec::from("test")).length(), BodyLength::Sized(4)); + assert_eq!(Body::from(Vec::from("test")).length(), BodySize::Sized(4)); assert_eq!(Body::from(Vec::from("test")).get_ref(), b"test"); } #[test] fn test_bytes() { - assert_eq!( - Body::from(Bytes::from("test")).length(), - BodyLength::Sized(4) - ); + assert_eq!(Body::from(Bytes::from("test")).length(), BodySize::Sized(4)); assert_eq!(Body::from(Bytes::from("test")).get_ref(), b"test"); } #[test] fn test_string() { let b = "test".to_owned(); - assert_eq!(Body::from(b.clone()).length(), BodyLength::Sized(4)); + assert_eq!(Body::from(b.clone()).length(), BodySize::Sized(4)); assert_eq!(Body::from(b.clone()).get_ref(), b"test"); - assert_eq!(Body::from(&b).length(), BodyLength::Sized(4)); + assert_eq!(Body::from(&b).length(), BodySize::Sized(4)); assert_eq!(Body::from(&b).get_ref(), b"test"); } #[test] fn test_bytes_mut() { let b = BytesMut::from("test"); - assert_eq!(Body::from(b.clone()).length(), BodyLength::Sized(4)); + assert_eq!(Body::from(b.clone()).length(), BodySize::Sized(4)); assert_eq!(Body::from(b).get_ref(), b"test"); } } diff --git a/actix-http/src/client/h1proto.rs b/actix-http/src/client/h1proto.rs index 2e29484ff..b7b8d4a0a 100644 --- a/actix-http/src/client/h1proto.rs +++ b/actix-http/src/client/h1proto.rs @@ -13,7 +13,7 @@ use crate::payload::{Payload, PayloadStream}; use super::connection::{ConnectionLifetime, ConnectionType, IoConnection}; use super::error::{ConnectError, SendRequestError}; use super::pool::Acquired; -use crate::body::{BodyLength, MessageBody}; +use crate::body::{BodySize, MessageBody}; pub(crate) fn send_request( io: T, @@ -40,7 +40,7 @@ where .from_err() // send request body .and_then(move |framed| match body.length() { - BodyLength::None | BodyLength::Empty | BodyLength::Sized(0) => { + BodySize::None | BodySize::Empty | BodySize::Sized(0) => { Either::A(ok(framed)) } _ => Either::B(SendBody::new(body, framed)), diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index 9ad722627..d45716ab8 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -8,7 +8,7 @@ use h2::{client::SendRequest, SendStream}; use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING}; use http::{request::Request, HttpTryFrom, Method, Version}; -use crate::body::{BodyLength, MessageBody}; +use crate::body::{BodySize, MessageBody}; use crate::message::{RequestHead, ResponseHead}; use crate::payload::Payload; @@ -31,7 +31,7 @@ where let head_req = head.method == Method::HEAD; let length = body.length(); let eof = match length { - BodyLength::None | BodyLength::Empty | BodyLength::Sized(0) => true, + BodySize::None | BodySize::Empty | BodySize::Sized(0) => true, _ => false, }; @@ -48,19 +48,19 @@ where // Content length let _ = match length { - BodyLength::None => None, - BodyLength::Stream => { + BodySize::None => None, + BodySize::Stream => { skip_len = false; None } - BodyLength::Empty => req + BodySize::Empty => req .headers_mut() .insert(CONTENT_LENGTH, HeaderValue::from_static("0")), - BodyLength::Sized(len) => req.headers_mut().insert( + BodySize::Sized(len) => req.headers_mut().insert( CONTENT_LENGTH, HeaderValue::try_from(format!("{}", len)).unwrap(), ), - BodyLength::Sized64(len) => req.headers_mut().insert( + BodySize::Sized64(len) => req.headers_mut().insert( CONTENT_LENGTH, HeaderValue::try_from(format!("{}", len)).unwrap(), ), diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 0778cc262..af861b9d7 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -9,7 +9,7 @@ use brotli2::write::BrotliEncoder; #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] use flate2::write::{GzEncoder, ZlibEncoder}; -use crate::body::{Body, BodyLength, MessageBody, ResponseBody}; +use crate::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::http::header::{ContentEncoding, CONTENT_ENCODING}; use crate::http::{HeaderValue, HttpTryFrom, StatusCode}; use crate::{Error, Head, ResponseHead}; @@ -89,14 +89,14 @@ enum EncoderBody { } impl MessageBody for Encoder { - fn length(&self) -> BodyLength { + fn length(&self) -> BodySize { if self.encoder.is_none() { match self.body { EncoderBody::Body(ref b) => b.length(), EncoderBody::Other(ref b) => b.length(), } } else { - BodyLength::Stream + BodySize::Stream } } diff --git a/actix-http/src/h1/client.rs b/actix-http/src/h1/client.rs index b3a5a5d9f..fbdc8bde1 100644 --- a/actix-http/src/h1/client.rs +++ b/actix-http/src/h1/client.rs @@ -12,7 +12,7 @@ use http::{Method, Version}; use super::decoder::{PayloadDecoder, PayloadItem, PayloadType}; use super::{decoder, encoder}; use super::{Message, MessageType}; -use crate::body::BodyLength; +use crate::body::BodySize; use crate::config::ServiceConfig; use crate::error::{ParseError, PayloadError}; use crate::helpers; @@ -179,7 +179,7 @@ impl Decoder for ClientPayloadCodec { } impl Encoder for ClientCodec { - type Item = Message<(RequestHead, BodyLength)>; + type Item = Message<(RequestHead, BodySize)>; type Error = io::Error; fn encode( diff --git a/actix-http/src/h1/codec.rs b/actix-http/src/h1/codec.rs index c66364c02..9bb417091 100644 --- a/actix-http/src/h1/codec.rs +++ b/actix-http/src/h1/codec.rs @@ -11,7 +11,7 @@ use http::{Method, StatusCode, Version}; use super::decoder::{PayloadDecoder, PayloadItem, PayloadType}; use super::{decoder, encoder}; use super::{Message, MessageType}; -use crate::body::BodyLength; +use crate::body::BodySize; use crate::config::ServiceConfig; use crate::error::ParseError; use crate::helpers; @@ -140,7 +140,7 @@ impl Decoder for Codec { } impl Encoder for Codec { - type Item = Message<(Response<()>, BodyLength)>; + type Item = Message<(Response<()>, BodySize)>; type Error = io::Error; fn encode( diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 09a17fcf7..34204bf5a 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -11,7 +11,7 @@ use futures::{Async, Future, Poll, Sink, Stream}; use log::{debug, error, trace}; use tokio_timer::Delay; -use crate::body::{Body, BodyLength, MessageBody, ResponseBody}; +use crate::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::config::ServiceConfig; use crate::error::DispatchError; use crate::error::{ParseError, PayloadError}; @@ -208,7 +208,7 @@ where self.flags .set(Flags::KEEPALIVE, self.framed.get_codec().keepalive()); match body.length() { - BodyLength::None | BodyLength::Empty => Ok(State::None), + BodySize::None | BodySize::Empty => Ok(State::None), _ => Ok(State::SendPayload(body)), } } diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 712d123eb..dbf6d440f 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -11,7 +11,7 @@ use http::header::{ }; use http::{HeaderMap, Method, StatusCode, Version}; -use crate::body::BodyLength; +use crate::body::BodySize; use crate::config::ServiceConfig; use crate::header::ContentEncoding; use crate::helpers; @@ -23,7 +23,7 @@ const AVERAGE_HEADER_SIZE: usize = 30; #[derive(Debug)] pub(crate) struct MessageEncoder { - pub length: BodyLength, + pub length: BodySize, pub te: TransferEncoding, _t: PhantomData, } @@ -31,7 +31,7 @@ pub(crate) struct MessageEncoder { impl Default for MessageEncoder { fn default() -> Self { MessageEncoder { - length: BodyLength::None, + length: BodySize::None, te: TransferEncoding::empty(), _t: PhantomData, } @@ -53,28 +53,28 @@ pub(crate) trait MessageType: Sized { &mut self, dst: &mut BytesMut, version: Version, - mut length: BodyLength, + mut length: BodySize, ctype: ConnectionType, config: &ServiceConfig, ) -> io::Result<()> { let chunked = self.chunked(); - let mut skip_len = length != BodyLength::Stream; + let mut skip_len = length != BodySize::Stream; // Content length if let Some(status) = self.status() { match status { StatusCode::NO_CONTENT | StatusCode::CONTINUE - | StatusCode::PROCESSING => length = BodyLength::None, + | StatusCode::PROCESSING => length = BodySize::None, StatusCode::SWITCHING_PROTOCOLS => { skip_len = true; - length = BodyLength::Stream; + length = BodySize::Stream; } _ => (), } } match length { - BodyLength::Stream => { + BodySize::Stream => { if chunked { dst.extend_from_slice(b"\r\ntransfer-encoding: chunked\r\n") } else { @@ -82,16 +82,16 @@ pub(crate) trait MessageType: Sized { dst.extend_from_slice(b"\r\n"); } } - BodyLength::Empty => { + BodySize::Empty => { dst.extend_from_slice(b"\r\ncontent-length: 0\r\n"); } - BodyLength::Sized(len) => helpers::write_content_length(len, dst), - BodyLength::Sized64(len) => { + BodySize::Sized(len) => helpers::write_content_length(len, dst), + BodySize::Sized64(len) => { dst.extend_from_slice(b"\r\ncontent-length: "); write!(dst.writer(), "{}", len)?; dst.extend_from_slice(b"\r\n"); } - BodyLength::None => dst.extend_from_slice(b"\r\n"), + BodySize::None => dst.extend_from_slice(b"\r\n"), } // Connection @@ -243,24 +243,24 @@ impl MessageEncoder { head: bool, stream: bool, version: Version, - length: BodyLength, + length: BodySize, ctype: ConnectionType, config: &ServiceConfig, ) -> io::Result<()> { // transfer encoding if !head { self.te = match length { - BodyLength::Empty => TransferEncoding::empty(), - BodyLength::Sized(len) => TransferEncoding::length(len as u64), - BodyLength::Sized64(len) => TransferEncoding::length(len), - BodyLength::Stream => { + BodySize::Empty => TransferEncoding::empty(), + BodySize::Sized(len) => TransferEncoding::length(len as u64), + BodySize::Sized64(len) => TransferEncoding::length(len), + BodySize::Stream => { if message.chunked() && !stream { TransferEncoding::chunked() } else { TransferEncoding::eof() } } - BodyLength::None => TransferEncoding::empty(), + BodySize::None => TransferEncoding::empty(), }; } else { self.te = TransferEncoding::empty(); diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index ea63dc2bc..9b43be669 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -18,7 +18,7 @@ use http::HttpTryFrom; use log::{debug, error, trace}; use tokio_timer::Delay; -use crate::body::{Body, BodyLength, MessageBody, ResponseBody}; +use crate::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::config::ServiceConfig; use crate::error::{DispatchError, Error, ParseError, PayloadError, ResponseError}; use crate::message::ResponseHead; @@ -151,10 +151,10 @@ where fn prepare_response( &self, head: &ResponseHead, - length: &mut BodyLength, + length: &mut BodySize, ) -> http::Response<()> { let mut has_date = false; - let mut skip_len = length != &BodyLength::Stream; + let mut skip_len = length != &BodySize::Stream; let mut res = http::Response::new(()); *res.status_mut() = head.status; @@ -164,23 +164,23 @@ where match head.status { http::StatusCode::NO_CONTENT | http::StatusCode::CONTINUE - | http::StatusCode::PROCESSING => *length = BodyLength::None, + | http::StatusCode::PROCESSING => *length = BodySize::None, http::StatusCode::SWITCHING_PROTOCOLS => { skip_len = true; - *length = BodyLength::Stream; + *length = BodySize::Stream; } _ => (), } let _ = match length { - BodyLength::None | BodyLength::Stream => None, - BodyLength::Empty => res + BodySize::None | BodySize::Stream => None, + BodySize::Empty => res .headers_mut() .insert(CONTENT_LENGTH, HeaderValue::from_static("0")), - BodyLength::Sized(len) => res.headers_mut().insert( + BodySize::Sized(len) => res.headers_mut().insert( CONTENT_LENGTH, HeaderValue::try_from(format!("{}", len)).unwrap(), ), - BodyLength::Sized64(len) => res.headers_mut().insert( + BodySize::Sized64(len) => res.headers_mut().insert( CONTENT_LENGTH, HeaderValue::try_from(format!("{}", len)).unwrap(), ), diff --git a/actix-http/src/service/senderror.rs b/actix-http/src/service/senderror.rs index 44d362593..03fe5976a 100644 --- a/actix-http/src/service/senderror.rs +++ b/actix-http/src/service/senderror.rs @@ -5,7 +5,7 @@ use actix_service::{NewService, Service}; use futures::future::{ok, Either, FutureResult}; use futures::{Async, Future, Poll, Sink}; -use crate::body::{BodyLength, MessageBody, ResponseBody}; +use crate::body::{BodySize, MessageBody, ResponseBody}; use crate::error::{Error, ResponseError}; use crate::h1::{Codec, Message}; use crate::response::Response; @@ -61,7 +61,7 @@ where let (res, _body) = res.replace_body(()); Either::B(SendErrorFut { framed: Some(framed), - res: Some((res, BodyLength::Empty).into()), + res: Some((res, BodySize::Empty).into()), err: Some(e), _t: PhantomData, }) @@ -71,7 +71,7 @@ where } pub struct SendErrorFut { - res: Option, BodyLength)>>, + res: Option, BodySize)>>, framed: Option>, err: Option, _t: PhantomData, @@ -172,7 +172,7 @@ where } pub struct SendResponseFut { - res: Option, BodyLength)>>, + res: Option, BodySize)>>, body: Option>, framed: Option>, } diff --git a/actix-http/src/ws/client/service.rs b/actix-http/src/ws/client/service.rs index 8a0840f90..cb3fb6f39 100644 --- a/actix-http/src/ws/client/service.rs +++ b/actix-http/src/ws/client/service.rs @@ -13,7 +13,7 @@ use log::trace; use rand; use sha1::Sha1; -use crate::body::BodyLength; +use crate::body::BodySize; use crate::h1; use crate::message::{ConnectionType, Head, ResponseHead}; use crate::ws::Codec; @@ -149,7 +149,7 @@ where // h1 protocol let framed = Framed::new(io, h1::ClientCodec::default()); framed - .send((request, BodyLength::None).into()) + .send((request, BodySize::None).into()) .map_err(ClientError::from) .and_then(|framed| { framed diff --git a/awc/src/lib.rs b/awc/src/lib.rs index ac7dcf2f1..3bad8caa3 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -1,12 +1,35 @@ +//! An HTTP Client +//! +//! ```rust +//! # use futures::future::{Future, lazy}; +//! use actix_rt::System; +//! use awc::Client; +//! +//! fn main() { +//! System::new("test").block_on(lazy(|| { +//! let mut client = Client::default(); +//! +//! client.get("http://www.rust-lang.org") // <- Create request builder +//! .header("User-Agent", "Actix-web") +//! .send() // <- Send http request +//! .map_err(|_| ()) +//! .and_then(|response| { // <- server http response +//! println!("Response: {:?}", response); +//! Ok(()) +//! }) +//! })); +//! } +//! ``` use std::cell::RefCell; use std::rc::Rc; pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError}; pub use actix_http::error::PayloadError; -pub use actix_http::{http, RequestHead}; +pub use actix_http::http; use actix_http::client::Connector; use actix_http::http::{HttpTryFrom, Method, Uri}; +use actix_http::RequestHead; mod builder; mod connect; @@ -20,7 +43,7 @@ pub use self::response::ClientResponse; use self::connect::{Connect, ConnectorWrapper}; -/// An HTTP Client Request +/// An HTTP Client /// /// ```rust /// # use futures::future::{Future, lazy}; diff --git a/awc/src/test.rs b/awc/src/test.rs index 165694d83..395e62904 100644 --- a/awc/src/test.rs +++ b/awc/src/test.rs @@ -1,5 +1,4 @@ -//! Test Various helpers for Actix applications to use during testing. - +//! Test helpers for actix http client to use during testing. use actix_http::http::header::{Header, IntoHeaderValue}; use actix_http::http::{HeaderName, HttpTryFrom, Version}; use actix_http::{h1, Payload, ResponseHead}; diff --git a/src/lib.rs b/src/lib.rs index a21032db6..54709b47b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,9 +106,6 @@ extern crate actix_web_codegen; #[doc(hidden)] pub use actix_web_codegen::*; -#[cfg(feature = "client")] -pub use awc as client; - // re-export for convenience pub use actix_http::Response as HttpResponse; pub use actix_http::{http, Error, HttpMessage, ResponseError, Result}; @@ -145,7 +142,7 @@ pub mod dev { pub use crate::types::payload::HttpMessageBody; pub use crate::types::readlines::Readlines; - pub use actix_http::body::{Body, BodyLength, MessageBody, ResponseBody}; + pub use actix_http::body::{Body, BodySize, MessageBody, ResponseBody}; pub use actix_http::ResponseBuilder as HttpResponseBuilder; pub use actix_http::{ Extensions, Head, Payload, PayloadStream, RequestHead, ResponseHead, @@ -371,3 +368,33 @@ pub mod web { fn_transform(f) } } + +#[cfg(feature = "client")] +pub mod client { + //! An HTTP Client + //! + //! ```rust + //! # use futures::future::{Future, lazy}; + //! use actix_rt::System; + //! use actix_web::client::Client; + //! + //! fn main() { + //! System::new("test").block_on(lazy(|| { + //! let mut client = Client::default(); + //! + //! client.get("http://www.rust-lang.org") // <- Create request builder + //! .header("User-Agent", "Actix-web") + //! .send() // <- Send http request + //! .map_err(|_| ()) + //! .and_then(|response| { // <- server http response + //! println!("Response: {:?}", response); + //! Ok(()) + //! }) + //! })); + //! } + //! ``` + pub use awc::{ + test, Client, ClientBuilder, ClientRequest, ClientResponse, ConnectError, + InvalidUrl, PayloadError, SendRequestError, + }; +} diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 42f344f03..cd52048f7 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -12,7 +12,7 @@ use futures::{Async, Future, Poll}; use regex::Regex; use time; -use crate::dev::{BodyLength, MessageBody, ResponseBody}; +use crate::dev::{BodySize, MessageBody, ResponseBody}; use crate::error::{Error, Result}; use crate::service::{ServiceRequest, ServiceResponse}; use crate::{HttpMessage, HttpResponse}; @@ -238,7 +238,7 @@ impl Drop for StreamLog { } impl MessageBody for StreamLog { - fn length(&self) -> BodyLength { + fn length(&self) -> BodySize { self.body.length() }