Trait viz_core::ResponseExt
source · pub trait ResponseExt: Sized {
Show 17 methods
// Required methods
fn content_length(&self) -> Option<u64>;
fn content_type(&self) -> Option<Mime>;
fn header<K, T>(&self, key: K) -> Option<T>
where K: AsHeaderName,
T: FromStr;
fn ok(&self) -> bool;
fn download<'life0, 'async_trait, T>(
path: T,
name: Option<&'life0 str>
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where T: AsRef<Path> + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn attachment(value: &str) -> Self;
fn location<T>(location: T) -> Self
where T: AsRef<str>;
fn redirect<T>(url: T) -> Self
where T: AsRef<str>;
fn redirect_with_status<T>(uri: T, status: StatusCode) -> Self
where T: AsRef<str>;
// Provided methods
fn with<B>(body: B, content_type: &'static str) -> Response
where B: Into<OutgoingBody> { ... }
fn text<B>(body: B) -> Response
where B: Into<Full<Bytes>> { ... }
fn html<B>(body: B) -> Response
where B: Into<Full<Bytes>> { ... }
fn json<T>(body: T) -> Result<Response, PayloadError>
where T: Serialize { ... }
fn stream<S, D, E>(stream: S) -> Response
where S: Stream<Item = Result<D, E>> + Send + Sync + 'static,
D: Into<Bytes> + 'static,
E: Into<Error> + 'static { ... }
fn see_other<T>(url: T) -> Self
where T: AsRef<str> { ... }
fn temporary<T>(url: T) -> Self
where T: AsRef<str> { ... }
fn permanent<T>(url: T) -> Self
where T: AsRef<str> { ... }
}
Expand description
The Response
Extension.
Required Methods§
sourcefn content_length(&self) -> Option<u64>
fn content_length(&self) -> Option<u64>
Get the size of this response’s body.
sourcefn content_type(&self) -> Option<Mime>
fn content_type(&self) -> Option<Mime>
Get the media type of this response.
sourcefn header<K, T>(&self, key: K) -> Option<T>where
K: AsHeaderName,
T: FromStr,
fn header<K, T>(&self, key: K) -> Option<T>where
K: AsHeaderName,
T: FromStr,
Get a header with the key.
sourcefn download<'life0, 'async_trait, T>(
path: T,
name: Option<&'life0 str>
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn download<'life0, 'async_trait, T>( path: T, name: Option<&'life0 str> ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
Available on crate feature
fs
only.Downloads transfers the file from path as an attachment.
sourcefn attachment(value: &str) -> Self
fn attachment(value: &str) -> Self
The Content-Disposition
header indicates if the content is expected to be
displayed inline in the browser, that is, as a Web page or as part of a Web page,
or as an attachment, that is downloaded and saved locally.
sourcefn location<T>(location: T) -> Self
fn location<T>(location: T) -> Self
The Content-Location
header indicates an alternate location for the returned data.
sourcefn redirect_with_status<T>(uri: T, status: StatusCode) -> Self
fn redirect_with_status<T>(uri: T, status: StatusCode) -> Self
The response redirects to the specified URL and the status code.
Provided Methods§
sourcefn with<B>(body: B, content_type: &'static str) -> Responsewhere
B: Into<OutgoingBody>,
fn with<B>(body: B, content_type: &'static str) -> Responsewhere
B: Into<OutgoingBody>,
The response with the specified Content-Type
.
sourcefn json<T>(body: T) -> Result<Response, PayloadError>where
T: Serialize,
fn json<T>(body: T) -> Result<Response, PayloadError>where
T: Serialize,
Available on crate feature
json
only.The response with application/javascript; charset=utf-8
media type.
Errors
Throws an error if serialization fails.
Object Safety§
This trait is not object safe.