Skip to main content

RequestBuilder

Struct RequestBuilder 

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

Builds a request.

let uri = Uri::sip(Host::Name(HostName::new("example.com")?));
let request = RequestBuilder::new(Method::Options, uri)
    .header(HeaderName::CallId, "abc123@example.com")?
    .max_forwards(70)
    .build();

Implementations§

Source§

impl RequestBuilder

Source

pub fn new(method: Method, uri: Uri) -> Self

Start a request.

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.

Distinct from Self::header because appending is right for Via and Route, where repetition is meaningful, and wrong for To or CSeq, where a second copy makes the message invalid.

Source

pub fn max_forwards(self, hops: u8) -> Self

Append a Max-Forwards header. Cannot fail: a u8 has no CRLF in it.

Source

pub fn cseq(self, sequence: u32, method: &Method) -> Result<Self, BuildError>

Append a CSeq header.

Source

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

Set the body, and the Content-Length that goes with it.

The two are set together because a body without a matching length is a framing bug waiting to happen, and there is no reason to let a caller create one.

Source

pub fn build(self) -> Request

Finish.

If no body was set, a Content-Length: 0 is added, because a stream transport cannot frame a message without one.

Trait Implementations§

Source§

impl Debug for RequestBuilder

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.