pub struct Response { /* private fields */ }Expand description
Express-style HTTP response.
Implementations§
Source§impl Response
impl Response
pub fn empty() -> Self
pub fn text(body: impl Into<String>) -> Self
pub fn html(body: impl Into<String>) -> Self
pub fn json<T: Serialize>(value: &T) -> Self
pub fn redirect(location: impl AsRef<str>) -> Self
Sourcepub fn bytes(data: impl Into<Bytes>, mime: &str) -> Self
pub fn bytes(data: impl Into<Bytes>, mime: &str) -> Self
Buffered body with an explicit MIME type.
Sourcepub fn attachment(self, filename: &str) -> Self
pub fn attachment(self, filename: &str) -> Self
Set Content-Disposition: attachment for downloads.
Sourcepub fn sse<S, E>(stream: S) -> Self
pub fn sse<S, E>(stream: S) -> Self
Server-Sent Events stream (text/event-stream).
Each item becomes one data: event (multi-line values split across data: lines).
pub fn stream(body: ResponseBody) -> Self
pub fn from_reader_stream<S>(stream: S) -> Self
pub fn header(self, name: impl AsRef<str>, value: impl AsRef<str>) -> Self
pub fn status_code(&self) -> StatusCode
pub fn headers(&self) -> &HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn take_body(&mut self) -> Body
pub fn set_body(&mut self, body: impl Into<Body>)
Sourcepub fn body_bytes(&self) -> Option<&[u8]>
pub fn body_bytes(&self) -> Option<&[u8]>
Body bytes when the response is buffered; None for streams.
Sourcepub async fn file(path: impl AsRef<Path>) -> Self
pub async fn file(path: impl AsRef<Path>) -> Self
Stream a local file (path-traversal safe relative to its parent directory).
Sourcepub async fn file_in(dir: impl AsRef<Path>, relative: impl AsRef<Path>) -> Self
pub async fn file_in(dir: impl AsRef<Path>, relative: impl AsRef<Path>) -> Self
Stream a file under dir / relative (path-traversal safe).
Sourcepub async fn download(path: impl AsRef<Path>) -> Self
pub async fn download(path: impl AsRef<Path>) -> Self
Self::file plus Content-Disposition: attachment.
Sourcepub async fn download_in(
dir: impl AsRef<Path>,
relative: impl AsRef<Path>,
) -> Self
pub async fn download_in( dir: impl AsRef<Path>, relative: impl AsRef<Path>, ) -> Self
Self::file_in plus Content-Disposition: attachment.
Trait Implementations§
Source§impl IntoResponse for Response
impl IntoResponse for Response
fn into_response(self) -> Response
Source§impl ResponseAssert for Response
impl ResponseAssert for Response
Source§fn assert_status(&self, code: u16) -> &Self
fn assert_status(&self, code: u16) -> &Self
Panic unless status matches
code.Source§fn json<T: DeserializeOwned>(&self) -> T
fn json<T: DeserializeOwned>(&self) -> T
Deserialize buffered JSON body; panics on failure.
Source§fn json_value(&self) -> Value
fn json_value(&self) -> Value
Parse buffered body as
serde_json::Value.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
Mutably borrows from an owned value. Read more