pub type ResponseBox = Response<Box<dyn Read + Send>>;
Expand description
A Response
without a template parameter.
Aliased Type§
struct ResponseBox { /* private fields */ }
Implementations
Source§impl<R> Response<R>where
R: Read,
impl<R> Response<R>where
R: Read,
Sourcepub fn new(
status_code: StatusCode,
headers: Vec<Header>,
data: R,
data_length: Option<usize>,
additional_headers: Option<Receiver<Header>>,
) -> Response<R>
pub fn new( status_code: StatusCode, headers: Vec<Header>, data: R, data_length: Option<usize>, additional_headers: Option<Receiver<Header>>, ) -> Response<R>
Creates a new Response object.
The additional_headers
argument is a receiver that
may provide headers even after the response has been sent.
All the other arguments are straight-forward.
Sourcepub fn with_chunked_threshold(self, length: usize) -> Response<R>
pub fn with_chunked_threshold(self, length: usize) -> Response<R>
Set a threshold for Content-Length
where we chose chunked
transfer. Notice that chunked transfer might happen regardless of
this threshold, for instance when the request headers indicate
it is wanted or when there is no Content-Length
.
Sourcepub fn into_reader(self) -> R
pub fn into_reader(self) -> R
Convert the response into the underlying Read
type.
This is mainly useful for testing as it must consume the Response
.
Sourcepub fn chunked_threshold(&self) -> usize
pub fn chunked_threshold(&self) -> usize
The current Content-Length
threshold for switching over to
chunked transfer. The default is 32768 bytes. Notice that
chunked transfer is mutually exclusive with sending a
Content-Length
header as per the HTTP spec.
Sourcepub fn add_header<H>(&mut self, header: H)
pub fn add_header<H>(&mut self, header: H)
Adds a header to the list. Does all the checks.
Sourcepub fn with_header<H>(self, header: H) -> Response<R>
pub fn with_header<H>(self, header: H) -> Response<R>
Returns the same request, but with an additional header.
Some headers cannot be modified and some other have a special behavior. See the documentation above.
Sourcepub fn with_status_code<S>(self, code: S) -> Response<R>where
S: Into<StatusCode>,
pub fn with_status_code<S>(self, code: S) -> Response<R>where
S: Into<StatusCode>,
Returns the same request, but with a different status code.
Sourcepub fn with_data<S>(self, reader: S, data_length: Option<usize>) -> Response<S>where
S: Read,
pub fn with_data<S>(self, reader: S, data_length: Option<usize>) -> Response<S>where
S: Read,
Returns the same request, but with different data.
Sourcepub fn raw_print<W: Write>(
self,
writer: W,
http_version: HTTPVersion,
request_headers: &[Header],
do_not_send_body: bool,
upgrade: Option<&str>,
) -> IoResult<()>
pub fn raw_print<W: Write>( self, writer: W, http_version: HTTPVersion, request_headers: &[Header], do_not_send_body: bool, upgrade: Option<&str>, ) -> IoResult<()>
Prints the HTTP response to a writer.
This function is the one used to send the response to the client’s socket. Therefore you shouldn’t expect anything pretty-printed or even readable.
The HTTP version and headers passed as arguments are used to decide which features (most notably, encoding) to use.
Note: does not flush the writer.
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Retrieves the current value of the Response
status code
Sourcepub fn data_length(&self) -> Option<usize>
pub fn data_length(&self) -> Option<usize>
Retrieves the current value of the Response
data length