mirror of
https://github.com/actix/actix-web.git
synced 2024-12-29 19:40:34 +00:00
rename BodyLength to BodySize
This commit is contained in:
parent
b6b37d3ea3
commit
faa3ea8e5b
18 changed files with 151 additions and 172 deletions
14
actix-http/.gitignore
vendored
14
actix-http/.gitignore
vendored
|
@ -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
|
|
@ -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 "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > 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
|
|
@ -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 = ".."
|
||||
|
||||
|
|
|
@ -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<Option<Bytes>, Error>;
|
||||
}
|
||||
|
||||
impl MessageBody for () {
|
||||
fn length(&self) -> BodyLength {
|
||||
BodyLength::Empty
|
||||
fn length(&self) -> BodySize {
|
||||
BodySize::Empty
|
||||
}
|
||||
|
||||
fn poll_next(&mut self) -> Poll<Option<Bytes>, Error> {
|
||||
|
@ -46,7 +46,7 @@ impl MessageBody for () {
|
|||
}
|
||||
|
||||
impl<T: MessageBody> MessageBody for Box<T> {
|
||||
fn length(&self) -> BodyLength {
|
||||
fn length(&self) -> BodySize {
|
||||
self.as_ref().length()
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ impl<B: MessageBody> ResponseBody<B> {
|
|||
}
|
||||
|
||||
impl<B: MessageBody> MessageBody for ResponseBody<B> {
|
||||
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<BytesMut> 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<Option<Bytes>, 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<Option<Bytes>, 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<Option<Bytes>, 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<Option<Bytes>, Error> {
|
||||
|
@ -297,8 +297,8 @@ impl MessageBody for &'static [u8] {
|
|||
}
|
||||
|
||||
impl MessageBody for Vec<u8> {
|
||||
fn length(&self) -> BodyLength {
|
||||
BodyLength::Sized(self.len())
|
||||
fn length(&self) -> BodySize {
|
||||
BodySize::Sized(self.len())
|
||||
}
|
||||
|
||||
fn poll_next(&mut self) -> Poll<Option<Bytes>, Error> {
|
||||
|
@ -314,8 +314,8 @@ impl MessageBody for Vec<u8> {
|
|||
}
|
||||
|
||||
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<Option<Bytes>, Error> {
|
||||
|
@ -354,8 +354,8 @@ where
|
|||
S: Stream<Item = Bytes, Error = E>,
|
||||
E: Into<Error>,
|
||||
{
|
||||
fn length(&self) -> BodyLength {
|
||||
BodyLength::Stream
|
||||
fn length(&self) -> BodySize {
|
||||
BodySize::Stream
|
||||
}
|
||||
|
||||
fn poll_next(&mut self) -> Poll<Option<Bytes>, Error> {
|
||||
|
@ -383,8 +383,8 @@ impl<S> MessageBody for SizedStream<S>
|
|||
where
|
||||
S: Stream<Item = Bytes, Error = Error>,
|
||||
{
|
||||
fn length(&self) -> BodyLength {
|
||||
BodyLength::Sized(self.size)
|
||||
fn length(&self) -> BodySize {
|
||||
BodySize::Sized(self.size)
|
||||
}
|
||||
|
||||
fn poll_next(&mut self) -> Poll<Option<Bytes>, 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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T, B>(
|
||||
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)),
|
||||
|
|
|
@ -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(),
|
||||
),
|
||||
|
|
|
@ -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<B> {
|
|||
}
|
||||
|
||||
impl<B: MessageBody> MessageBody for Encoder<B> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T: MessageType> {
|
||||
pub length: BodyLength,
|
||||
pub length: BodySize,
|
||||
pub te: TransferEncoding,
|
||||
_t: PhantomData<T>,
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ pub(crate) struct MessageEncoder<T: MessageType> {
|
|||
impl<T: MessageType> Default for MessageEncoder<T> {
|
||||
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<T: MessageType> MessageEncoder<T> {
|
|||
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();
|
||||
|
|
|
@ -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(),
|
||||
),
|
||||
|
|
|
@ -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<T, R, E> {
|
||||
res: Option<Message<(Response<()>, BodyLength)>>,
|
||||
res: Option<Message<(Response<()>, BodySize)>>,
|
||||
framed: Option<Framed<T, Codec>>,
|
||||
err: Option<E>,
|
||||
_t: PhantomData<R>,
|
||||
|
@ -172,7 +172,7 @@ where
|
|||
}
|
||||
|
||||
pub struct SendResponseFut<T, B> {
|
||||
res: Option<Message<(Response<()>, BodyLength)>>,
|
||||
res: Option<Message<(Response<()>, BodySize)>>,
|
||||
body: Option<ResponseBody<B>>,
|
||||
framed: Option<Framed<T, Codec>>,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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};
|
||||
|
|
35
src/lib.rs
35
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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<B> Drop for StreamLog<B> {
|
|||
}
|
||||
|
||||
impl<B: MessageBody> MessageBody for StreamLog<B> {
|
||||
fn length(&self) -> BodyLength {
|
||||
fn length(&self) -> BodySize {
|
||||
self.body.length()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue