Skip to main content

Response

Struct Response 

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

An HTTP response.

use giong_http::Response;

let ok = Response::json(r#"{"ok":true}"#);
let missing = Response::new(404).header("Cache-Control", "no-store").body("not found");

Implementations§

Source§

impl Response

Source

pub fn new(status: u16) -> Self

A response with the given status code and no body.

§Panics

Panics if status is not in 200..=599. Interim (1xx) responses are sent by the server itself.

Source

pub fn text(body: impl Into<Body>) -> Self

200 OK with a text/plain; charset=utf-8 body.

Source

pub fn json(body: impl Into<Body>) -> Self

200 OK with an application/json body.

Source

pub fn header(self, name: &str, value: &str) -> Self

Adds a header field.

Content-Length, Transfer-Encoding, Connection and Date are managed by the server; setting them here is ignored.

§Panics

Panics if name is not a valid header name or value contains control characters. Building headers from untrusted input without checking it would otherwise allow response splitting.

Source

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

Sets the body.

Source

pub fn status(&self) -> u16

The status code.

Trait Implementations§

Source§

impl Debug for Response

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.