[][src]Struct tiny_http::Response

pub struct Response<R> where
    R: Read
{ /* fields omitted */ }

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.

Methods

impl<R> Response<R> where
    R: Read
[src]

pub fn new(
    status_code: StatusCode,
    headers: Vec<Header>,
    data: R,
    data_length: Option<usize>,
    additional_headers: Option<Receiver<Header>>
) -> Response<R>
[src]

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.

pub fn with_chunked_threshold(self, length: usize) -> Response<R>[src]

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.

pub fn chunked_threshold(&self) -> usize[src]

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.

pub fn add_header<H>(&mut self, header: H) where
    H: Into<Header>, 
[src]

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

pub fn with_header<H>(self, header: H) -> Response<R> where
    H: Into<Header>, 
[src]

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.

pub fn with_status_code<S>(self, code: S) -> Response<R> where
    S: Into<StatusCode>, 
[src]

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

pub fn with_data<S>(self, reader: S, data_length: Option<usize>) -> Response<S> where
    S: Read
[src]

Returns the same request, but with different data.

pub fn raw_print<W: Write>(
    self,
    writer: W,
    http_version: HTTPVersion,
    request_headers: &[Header],
    do_not_send_body: bool,
    upgrade: Option<&str>
) -> IoResult<()>
[src]

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.

impl<R> Response<R> where
    R: Read + Send + 'static, 
[src]

pub fn boxed(self) -> ResponseBox[src]

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

impl Response<File>[src]

pub fn from_file(file: File) -> Response<File>[src]

Builds a new Response from a File.

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

impl Response<Cursor<Vec<u8>>>[src]

pub fn from_data<D>(data: D) -> Response<Cursor<Vec<u8>>> where
    D: Into<Vec<u8>>, 
[src]

pub fn from_string<S>(data: S) -> Response<Cursor<Vec<u8>>> where
    S: Into<String>, 
[src]

impl Response<Empty>[src]

pub fn empty<S>(status_code: S) -> Response<Empty> where
    S: Into<StatusCode>, 
[src]

Builds an empty Response with the given status code.

pub fn new_empty(status_code: StatusCode) -> Response<Empty>[src]

DEPRECATED. Use empty instead.

Trait Implementations

impl Clone for Response<Empty>[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for Response<R> where
    R: RefUnwindSafe

impl<R> Send for Response<R> where
    R: Send

impl<R> Sync for Response<R> where
    R: Sync

impl<R> Unpin for Response<R> where
    R: Unpin

impl<R> UnwindSafe for Response<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.