Skip to main content

ResponseBuilder

Struct ResponseBuilder 

Source
pub struct ResponseBuilder { /* private fields */ }
Expand description

Builds a response.

Implementations§

Source§

impl ResponseBuilder

Source

pub fn new( status: StatusCode, reason: impl Into<Bytes>, ) -> Result<Self, BuildError>

Start a response.

The reason phrase is checked: it is the one field on a start line that carries free text, which makes it the obvious place to try to inject a line break.

Source

pub fn to_request( request: &Request, status: StatusCode, reason: impl Into<Bytes>, ) -> Result<Self, BuildError>

Start a response to a request, copying the headers RFC 3261 §8.2.6.2 requires.

Via is copied in order and in full: the response finds its way back by walking that list, and reordering or deduplicating it strands the response. From, To, Call-ID and CSeq are copied verbatim, which also means a request whose To was unparseable still gets a well-formed response — the point of copying rather than re-deriving.

Source

pub fn header( self, name: HeaderName, value: impl Into<Bytes>, ) -> Result<Self, BuildError>

Append a header, rejecting a value that could inject a line break.

Source

pub fn set_header( self, name: &HeaderName, value: impl Into<Bytes>, ) -> Result<Self, BuildError>

Replace every header of this name with one carrying this value.

Source

pub fn body(self, body: impl Into<Bytes>) -> Self

Set the body and its Content-Length.

Source

pub fn build(self) -> Response

Finish.

Trait Implementations§

Source§

impl Debug for ResponseBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.