Struct tiny_http::Response

source ·
pub struct Response<R>where
    R: Read,
{ /* private fields */ }
Expand description

Object representing an HTTP response whose purpose is to be given to a Request.

Some headers cannot be changed. Trying to define the value of one of these will have no effect:

  • Accept-Ranges
  • Connection
  • Content-Range
  • Trailer
  • Transfer-Encoding
  • Upgrade

Some headers have special behaviors:

  • Content-Encoding: If you define this header, the library will assume that the data from the Read object has the specified encoding and will just pass-through.

  • Content-Length: The length of the data should be set manually using the Reponse object’s API. Attempting to set the value of this header will be equivalent to modifying the size of the data but the header itself may not be present in the final result.

Implementations

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.

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.

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.

Adds a header to the list. Does all the checks.

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.

Returns the same request, but with a different status code.

Returns the same request, but with different data.

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.

Turns this response into a Response<Box<Read + Send>>.

Builds a new Response from a File.

The Content-Type will not be automatically detected, you must set it yourself.

Builds an empty Response with the given status code.

DEPRECATED. Use empty instead.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.