pub struct Response {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Body,
}Expand description
An HTTP response.
Fields§
§status: StatusCode§headers: HeaderMap§body: BodyImplementations§
Source§impl Response
impl Response
pub fn new(status: StatusCode, body: Body) -> Self
pub fn text(body: impl Into<String>) -> Self
pub fn html(body: impl Into<String>) -> Self
Sourcepub fn json<T: Serialize + ?Sized>(data: &T) -> Self
pub fn json<T: Serialize + ?Sized>(data: &T) -> Self
JSON response. Serialization failures produce a 500.
pub fn bytes(body: impl Into<Bytes>) -> Self
Sourcepub fn permanent_redirect(location: &str) -> Self
pub fn permanent_redirect(location: &str) -> Self
Permanent redirect (308).
pub fn redirect_with(location: &str, status: StatusCode) -> Self
pub fn not_found() -> Self
pub fn with_status(self, code: u16) -> Self
Sourcepub fn with_header(self, name: &str, value: &str) -> Self
pub fn with_header(self, name: &str, value: &str) -> Self
Set a header. Invalid names or values (e.g. containing CR/LF) are rejected, which prevents header injection; they are logged and dropped.
pub fn set_header(&mut self, name: &str, value: &str) -> bool
pub fn append_header(&mut self, name: &str, value: &str) -> bool
pub fn with_content_type(self, ct: &'static str) -> Self
pub fn with_cache_control(self, value: &str) -> Self
Add a cookie to the response.
pub fn header(&self, name: &str) -> Option<&str>
Sourcepub async fn into_bytes(self) -> Result<Bytes, BoxError>
pub async fn into_bytes(self) -> Result<Bytes, BoxError>
Collect the body into bytes (tests and adapters).
Trait Implementations§
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 !Sync for Response
impl !UnwindSafe for Response
impl Forget for Response
impl Move for Response
impl Send 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