pub struct HttpResponseBuilder { /* private fields */ }Expand description
A builder for creating HttpResponse instances fluently using the builder pattern.
This allows for chaining method calls to configure a response, improving readability.
Implementations§
Source§impl HttpResponseBuilder
impl HttpResponseBuilder
Sourcepub fn new(status: StatusCode) -> Self
pub fn new(status: StatusCode) -> Self
Creates a new builder with a given status code.
Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
pub fn body(self, body: impl Into<Bytes>) -> Self
Sets the response body.
This method is generic over impl Into<Bytes>, allowing various types like
Vec<u8>, String, or &'static str to be passed as the body.
Sourcepub fn header(self, header: HttpHeader) -> Self
pub fn header(self, header: HttpHeader) -> Self
Adds a single HTTP header to the response.
If the headers vector doesn’t exist yet, it will be created.
Sourcepub fn headers(self, headers: Vec<HttpHeader>) -> Self
pub fn headers(self, headers: Vec<HttpHeader>) -> Self
Appends multiple HTTP headers to the response.
Sourcepub fn max_age(self, seconds: u32, is_private: bool) -> Self
pub fn max_age(self, seconds: u32, is_private: bool) -> Self
Sets the Cache-Control max-age and privacy directive.
Sourcepub fn finish(self) -> HttpResponse
pub fn finish(self) -> HttpResponse
Consumes the builder and returns the final HttpResponse instance.
Trait Implementations§
Source§impl Debug for HttpResponseBuilder
impl Debug for HttpResponseBuilder
Source§impl Default for HttpResponseBuilder
impl Default for HttpResponseBuilder
Source§fn default() -> HttpResponseBuilder
fn default() -> HttpResponseBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for HttpResponseBuilder
impl RefUnwindSafe for HttpResponseBuilder
impl Send for HttpResponseBuilder
impl Sync for HttpResponseBuilder
impl Unpin for HttpResponseBuilder
impl UnsafeUnpin for HttpResponseBuilder
impl UnwindSafe for HttpResponseBuilder
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