pub struct HttpResponse {
pub status: HttpStatus,
pub headers: HashMap<String, String>,
pub body: Vec<u8>,
}Expand description
Outgoing HTTP response.
Fields§
§status: HttpStatusHTTP status code.
headers: HashMap<String, String>Response headers.
body: Vec<u8>Response body.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(status: HttpStatus) -> HttpResponse
pub fn new(status: HttpStatus) -> HttpResponse
Creates a new HTTP response with the given status.
Sourcepub fn ok() -> HttpResponse
pub fn ok() -> HttpResponse
Creates a 200 OK response.
Sourcepub fn bad_request() -> HttpResponse
pub fn bad_request() -> HttpResponse
Creates a 400 Bad Request response.
Sourcepub fn internal_error() -> HttpResponse
pub fn internal_error() -> HttpResponse
Creates a 500 Internal Server Error response.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> HttpResponse
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> HttpResponse
Adds a header.
Sourcepub fn with_json<T>(self, value: &T) -> HttpResponsewhere
T: Serialize,
pub fn with_json<T>(self, value: &T) -> HttpResponsewhere
T: Serialize,
Sets the body as JSON.
Sourcepub fn with_cors(self, origin: &str) -> HttpResponse
pub fn with_cors(self, origin: &str) -> HttpResponse
Sets CORS headers for cross-origin requests.
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
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
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: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).