Struct saphir::SyncResponse
source · pub struct SyncResponse { /* private fields */ }
Expand description
A Structure which represent a fully mutable http response
Implementations
sourceimpl SyncResponse
impl SyncResponse
sourcepub fn status<T>(&mut self, status: T) -> &mut SyncResponsewhere
StatusCode: HttpTryFrom<T>,
pub fn status<T>(&mut self, status: T) -> &mut SyncResponsewhere
StatusCode: HttpTryFrom<T>,
Set the HTTP status for this response.
This function will configure the HTTP status code of the Response
that
will be returned from Builder::build
.
By default this is 200
.
Examples
let response = SyncResponse::new()
.status(200)
.build_response()
.unwrap();
sourcepub fn version(&mut self, version: Version) -> &mut SyncResponse
pub fn version(&mut self, version: Version) -> &mut SyncResponse
Set the HTTP version for this response.
This function will configure the HTTP version of the Response
that
will be returned from Builder::build
.
By default this is HTTP/1.1
Examples
let response = SyncResponse::new()
.version(Version::HTTP_2)
.build_response()
.unwrap();
sourcepub fn header<K, V>(&mut self, key: K, value: V) -> &mut SyncResponsewhere
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut SyncResponsewhere
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>,
Appends a header to this response builder.
This function will append the provided key/value as a header to the
internal HeaderMap
being constructed. Essentially this is equivalent
to calling HeaderMap::append
.
Examples
let response = SyncResponse::new()
.header("Content-Type", "text/html")
.header("X-Custom-Foo", "bar")
.build_response()
.unwrap();
sourcepub fn parsed_header(&mut self, headers: Headers) -> &mut SyncResponse
pub fn parsed_header(&mut self, headers: Headers) -> &mut SyncResponse
A convinient function to constuct the response headers from a Headers struct
sourcepub fn extension<T>(&mut self, extension: T) -> &mut SyncResponsewhere
T: Any + Send + Sync + 'static,
pub fn extension<T>(&mut self, extension: T) -> &mut SyncResponsewhere
T: Any + Send + Sync + 'static,
Adds an extension to this builder
Examples
let response = SyncResponse::new()
.extension("My Extension")
.build_response()
.unwrap();
assert_eq!(response.extensions().get::<&'static str>(),
Some(&"My Extension"));
sourcepub fn body<B: 'static + ToBody>(&mut self, body: B) -> &mut SyncResponse
pub fn body<B: 'static + ToBody>(&mut self, body: B) -> &mut SyncResponse
Adds a body to a response
Examples
let response = SyncResponse::new()
.body(b"this is a payload")
.build_response()
.unwrap();
Auto Trait Implementations
impl !RefUnwindSafe for SyncResponse
impl !Send for SyncResponse
impl !Sync for SyncResponse
impl Unpin for SyncResponse
impl !UnwindSafe for SyncResponse
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more