mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 06:57:43 +02:00
simplify AnyBody
and BodySize
(#2446)
This commit is contained in:
@ -70,7 +70,7 @@ where
|
||||
// RFC: https://tools.ietf.org/html/rfc7231#section-5.1.1
|
||||
let is_expect = if head.as_ref().headers.contains_key(EXPECT) {
|
||||
match body.size() {
|
||||
BodySize::None | BodySize::Empty | BodySize::Sized(0) => {
|
||||
BodySize::None | BodySize::Sized(0) => {
|
||||
let keep_alive = framed.codec_ref().keepalive();
|
||||
framed.io_mut().on_release(keep_alive);
|
||||
|
||||
@ -104,7 +104,7 @@ where
|
||||
if do_send {
|
||||
// send request body
|
||||
match body.size() {
|
||||
BodySize::None | BodySize::Empty | BodySize::Sized(0) => {}
|
||||
BodySize::None | BodySize::Sized(0) => {}
|
||||
_ => send_body(body, pin_framed.as_mut()).await?,
|
||||
};
|
||||
|
||||
|
@ -36,10 +36,7 @@ where
|
||||
|
||||
let head_req = head.as_ref().method == Method::HEAD;
|
||||
let length = body.size();
|
||||
let eof = matches!(
|
||||
length,
|
||||
BodySize::None | BodySize::Empty | BodySize::Sized(0)
|
||||
);
|
||||
let eof = matches!(length, BodySize::None | BodySize::Sized(0));
|
||||
|
||||
let mut req = Request::new(());
|
||||
*req.uri_mut() = head.as_ref().uri.clone();
|
||||
@ -52,13 +49,11 @@ where
|
||||
// Content length
|
||||
let _ = match length {
|
||||
BodySize::None => None,
|
||||
BodySize::Stream => {
|
||||
skip_len = false;
|
||||
None
|
||||
}
|
||||
BodySize::Empty => req
|
||||
|
||||
BodySize::Sized(0) => req
|
||||
.headers_mut()
|
||||
.insert(CONTENT_LENGTH, HeaderValue::from_static("0")),
|
||||
|
||||
BodySize::Sized(len) => {
|
||||
let mut buf = itoa::Buffer::new();
|
||||
|
||||
@ -67,6 +62,11 @@ where
|
||||
HeaderValue::from_str(buf.format(len)).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
BodySize::Stream => {
|
||||
skip_len = false;
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Extracting extra headers from RequestHeadType. HeaderMap::new() does not allocate.
|
||||
|
@ -194,7 +194,7 @@ where
|
||||
match body {
|
||||
Some(ref bytes) => Body::Bytes(bytes.clone()),
|
||||
// TODO: should this be Body::Empty or Body::None.
|
||||
_ => Body::Empty,
|
||||
_ => Body::empty(),
|
||||
}
|
||||
} else {
|
||||
body = None;
|
||||
|
@ -297,7 +297,7 @@ impl RequestSender {
|
||||
timeout: Option<Duration>,
|
||||
config: &ClientConfig,
|
||||
) -> SendClientRequest {
|
||||
self.send_body(addr, response_decompress, timeout, config, Body::Empty)
|
||||
self.send_body(addr, response_decompress, timeout, config, Body::empty())
|
||||
}
|
||||
|
||||
fn set_header_if_none<V>(&mut self, key: HeaderName, value: V) -> Result<(), HttpError>
|
||||
|
Reference in New Issue
Block a user