Response

Struct Response 

Source
pub struct Response {
    pub kind: ResponseKind,
    pub code: u16,
    pub content_type: ContentType,
    pub headers: HeaderList,
    pub body: ResponseBody,
}

Fields§

§kind: ResponseKind§code: u16§content_type: ContentType§headers: HeaderList§body: ResponseBody

Implementations§

Source§

impl Response

Source

pub fn new(code: u16) -> Self

Source

pub fn drop_connection() -> Self

Return this and the server will drop the connection.

Source

pub fn get_body_and_reprocess(max_len: u64) -> Self

Return this and the server will read the request body from the client and call the request handler again.

If the request body is larger than max_len bytes, it sends 413 Payload Too Large.

Source

pub fn html(code: u16, body: impl Into<ResponseBody>) -> Self

Source

pub fn event_stream() -> (EventSender, Response)

Source

pub fn text(code: u16, body: impl Into<ResponseBody>) -> Self

Source

pub fn ok_200() -> Self

Source

pub fn no_content_204() -> Self

Source

pub fn redirect_301(location: impl AsRef<str>) -> Self

Tell the client to GET location.

The client should store this redirect.

§Panics

Panics when location is not US-ASCII.

Source

pub fn redirect_303(location: impl AsRef<str>) -> Self

Tell the client to GET location.

The client should not store this redirect.

A PUT or POST handler usually returns this.

§Panics

Panics when location is not US-ASCII.

Source

pub fn unauthorized_401() -> Self

Source

pub fn forbidden_403() -> Self

Source

pub fn not_found_404() -> Self

Source

pub fn method_not_allowed_405(allowed_methods: &[&'static str]) -> Self

§Panics

Panics when any of allowed_methods are not US-ASCII.

Source

pub fn length_required_411() -> Self

Source

pub fn payload_too_large_413() -> Self

Source

pub fn unprocessable_entity_422(body: impl Into<String>) -> Self

Source

pub fn too_many_requests_429() -> Self

Source

pub fn internal_server_error_500() -> Self

Source

pub fn not_implemented_501() -> Self

Source

pub fn service_unavailable_503() -> Self

Source

pub fn with_body(self, b: impl Into<ResponseBody>) -> Self

Source

pub fn with_max_age_seconds(self, seconds: u32) -> Self

Source

pub fn with_no_store(self) -> Self

Source

pub fn with_header(self, name: impl AsRef<str>, value: AsciiString) -> Self

Adds a header.

You can call this multiple times to add multiple headers with the same name.

The HTTP spec limits header names to US-ASCII and header values to US-ASCII or ISO-8859-1.

§Panics

Panics when name is not US-ASCII.

§Example
use servlin::Response;

return Response::new(200)
    .with_header("header1", "value1".to_string().try_into().unwrap());
Source

pub fn with_status(self, c: u16) -> Self

Source

pub fn with_type(self, t: ContentType) -> Self

Source

pub fn is_1xx(&self) -> bool

Source

pub fn is_2xx(&self) -> bool

Source

pub fn is_3xx(&self) -> bool

Source

pub fn is_4xx(&self) -> bool

Source

pub fn is_5xx(&self) -> bool

Source

pub fn is_normal(&self) -> bool

Source

pub fn is_get_body_and_reprocess(&self) -> bool

Trait Implementations§

Source§

impl Debug for Response

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<Error> for Response

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<HttpError> for Response

Source§

fn from(e: HttpError) -> Self

Converts to this type from the input type.
Source§

impl From<Response> for Error

Source§

fn from(value: Response) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Response

Source§

fn eq(&self, other: &Response) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Response

Source§

impl StructuralPartialEq for Response

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more