pub struct Response { /* private fields */ }Expand description
A fully buffered HTTP response.
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(status: StatusCode) -> Self
pub fn new(status: StatusCode) -> Self
An empty response with the given status.
pub fn text(body: impl Into<String>) -> Self
pub fn html(body: impl Into<String>) -> Self
Sourcepub fn json<T: Serialize + ?Sized>(value: &T) -> Self
pub fn json<T: Serialize + ?Sized>(value: &T) -> Self
Serializes value as JSON. Serialization failures become a 500.
With escape_html_entities_in_json on, <, > and & are
written \u003c, \u003e and \u0026, as Rails writes them.
Sourcepub fn redirect(location: &str) -> Self
pub fn redirect(location: &str) -> Self
A 303 See Other redirect, the right status after a form submission.
Sourcepub fn download(bytes: impl Into<Bytes>, filename: &str) -> Self
pub fn download(bytes: impl Into<Bytes>, filename: &str) -> Self
A file for the browser to save, as Rails’ send_data: its type
from the name’s extension (application/octet-stream if unknown)
and a Content-Disposition: attachment naming it.
Sourcepub fn inline(bytes: impl Into<Bytes>, filename: &str) -> Self
pub fn inline(bytes: impl Into<Bytes>, filename: &str) -> Self
A file for the browser to show, such as a PDF in its viewer, as
Rails’ send_data …, disposition: "inline".
Sourcepub fn head(status: StatusCode) -> Self
pub fn head(status: StatusCode) -> Self
A response with only a status and no body, as Rails’ head :ok.
Error statuses stay empty too: Pipeline::api leaves them be.
pub fn no_content() -> Self
Sourcepub fn with_body_bytes(self, body: impl Into<Bytes>) -> Self
pub fn with_body_bytes(self, body: impl Into<Bytes>) -> Self
Replaces the body, leaving headers untouched.
pub fn with_status(self, status: StatusCode) -> Self
Sourcepub fn with_header<K, V>(self, name: K, value: V) -> Self
pub fn with_header<K, V>(self, name: K, value: V) -> Self
Sets a header, replacing any existing value. Invalid names or values are dropped with a warning rather than panicking mid-request.
pub fn status(&self) -> StatusCode
pub fn headers(&self) -> &HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn header(&self, name: impl AsHeaderName) -> Option<&str>
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Data attached for middleware further up the stack; never sent to the client.
pub fn extensions_mut(&mut self) -> &mut Extensions
pub fn body(&self) -> &Bytes
Sourcepub fn fresh_when(self, ctx: &Context, last_modified: DateTime<Utc>) -> Self
pub fn fresh_when(self, ctx: &Context, last_modified: DateTime<Utc>) -> Self
This response for a conditional GET, as Rails’ stale?/fresh_when:
it gets Last-Modified and a weak ETag of its body, and becomes an
empty 304 Not Modified when the request’s If-None-Match matches
the ETag, or (without one) its If-Modified-Since isn’t older than
last_modified.
Response::json(&action).fresh_when(&ctx, action.updated_at.and_utc())Trait Implementations§
Source§impl From<Response> for TestResponse
impl From<Response> for TestResponse
Source§impl IntoResponse for Response
impl IntoResponse for Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl !Freeze for Response
impl !RefUnwindSafe for Response
impl !UnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more