mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
improve body size docs
This commit is contained in:
parent
68d1bd88b1
commit
0404b78b54
@ -15,13 +15,39 @@ use crate::error::Error;
|
|||||||
/// Body size hint.
|
/// Body size hint.
|
||||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||||
pub enum BodySize {
|
pub enum BodySize {
|
||||||
|
/// Absence of body can be assumed from method or status code.
|
||||||
|
///
|
||||||
|
/// Will skip writing Content-Length header.
|
||||||
None,
|
None,
|
||||||
|
|
||||||
|
/// Zero size body.
|
||||||
|
///
|
||||||
|
/// Will write `Content-Length: 0` header.
|
||||||
Empty,
|
Empty,
|
||||||
|
|
||||||
|
/// Known size body.
|
||||||
|
///
|
||||||
|
/// Will write `Content-Length: N` header. `Sized(0)` is treated the same as `Empty`.
|
||||||
Sized(u64),
|
Sized(u64),
|
||||||
|
|
||||||
|
/// Unknown size body.
|
||||||
|
///
|
||||||
|
/// Will not write Content-Length header. Can be used with chunked Transfer-Encoding.
|
||||||
Stream,
|
Stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BodySize {
|
impl BodySize {
|
||||||
|
/// Returns true if size hint indicates no or empty body.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use actix_http::body::BodySize;
|
||||||
|
/// assert!(BodySize::None.is_eof());
|
||||||
|
/// assert!(BodySize::Empty.is_eof());
|
||||||
|
/// assert!(BodySize::Sized(0).is_eof());
|
||||||
|
///
|
||||||
|
/// assert!(!BodySize::Sized(64).is_eof());
|
||||||
|
/// assert!(!BodySize::Stream.is_eof());
|
||||||
|
/// ```
|
||||||
pub fn is_eof(&self) -> bool {
|
pub fn is_eof(&self) -> bool {
|
||||||
matches!(self, BodySize::None | BodySize::Empty | BodySize::Sized(0))
|
matches!(self, BodySize::None | BodySize::Empty | BodySize::Sized(0))
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ where
|
|||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
trace!("Sending client request: {:?} {:?}", head, body.size());
|
trace!("Sending client request: {:?} {:?}", head, body.size());
|
||||||
|
|
||||||
let head_req = head.as_ref().method == Method::HEAD;
|
let head_req = head.as_ref().method == Method::HEAD;
|
||||||
let length = body.size();
|
let length = body.size();
|
||||||
let eof = matches!(
|
let eof = matches!(
|
||||||
|
@ -78,6 +78,7 @@ impl<B: MessageBody> Encoder<B> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseBody::Body(Encoder {
|
ResponseBody::Body(Encoder {
|
||||||
body,
|
body,
|
||||||
eof: false,
|
eof: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user