mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-24 22:37:35 +02:00
rename BodyLength to BodySize
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user