Struct hyper_staticfile::ResponseBuilder
source · pub struct ResponseBuilder<'a> {
pub path: &'a str,
pub query: Option<&'a str>,
pub file_response_builder: FileResponseBuilder,
}
Expand description
Utility to build the default response for a resolve
result.
This struct allows direct access to its fields, but these fields are typically initialized by the accessors, using the builder pattern. The fields are basically a bunch of settings that determine the response details.
Fields§
§path: &'a str
The request path.
query: Option<&'a str>
The request query string.
file_response_builder: FileResponseBuilder
Inner file response builder.
Implementations§
source§impl<'a> ResponseBuilder<'a>
impl<'a> ResponseBuilder<'a>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with a default configuration.
Examples found in repository?
src/service.rs (line 57)
51 52 53 54 55 56 57 58 59 60 61 62 63
pub async fn serve<B>(self, request: Request<B>) -> Result<Response<Body>, IoError> {
let Self {
root,
cache_headers,
} = self;
resolve(root, &request).await.map(|result| {
ResponseBuilder::new()
.request(&request)
.cache_headers(cache_headers)
.build(result)
.expect("unable to build response")
})
}
sourcepub fn request<B>(&mut self, req: &'a Request<B>) -> &mut Self
pub fn request<B>(&mut self, req: &'a Request<B>) -> &mut Self
Apply parameters based on a request.
Examples found in repository?
src/service.rs (line 58)
51 52 53 54 55 56 57 58 59 60 61 62 63
pub async fn serve<B>(self, request: Request<B>) -> Result<Response<Body>, IoError> {
let Self {
root,
cache_headers,
} = self;
resolve(root, &request).await.map(|result| {
ResponseBuilder::new()
.request(&request)
.cache_headers(cache_headers)
.build(result)
.expect("unable to build response")
})
}
sourcepub fn request_parts(
&mut self,
method: &Method,
uri: &'a Uri,
headers: &'a HeaderMap
) -> &mut Self
pub fn request_parts(
&mut self,
method: &Method,
uri: &'a Uri,
headers: &'a HeaderMap
) -> &mut Self
Apply parameters based on request parts.
sourcepub fn request_uri(&mut self, uri: &'a Uri) -> &mut Self
pub fn request_uri(&mut self, uri: &'a Uri) -> &mut Self
Apply parameters based on a request URI.
sourcepub fn cache_headers(&mut self, value: Option<u32>) -> &mut Self
pub fn cache_headers(&mut self, value: Option<u32>) -> &mut Self
Add cache headers to responses for the given lifespan.
Examples found in repository?
src/service.rs (line 59)
51 52 53 54 55 56 57 58 59 60 61 62 63
pub async fn serve<B>(self, request: Request<B>) -> Result<Response<Body>, IoError> {
let Self {
root,
cache_headers,
} = self;
resolve(root, &request).await.map(|result| {
ResponseBuilder::new()
.request(&request)
.cache_headers(cache_headers)
.build(result)
.expect("unable to build response")
})
}
sourcepub fn build(&self, result: ResolveResult) -> Result<Response<Body>>
pub fn build(&self, result: ResolveResult) -> Result<Response<Body>>
Build a response for the given request and resolve
result.
This function may error if it response could not be constructed, but this should be a seldom occurrence.
Examples found in repository?
src/service.rs (line 60)
51 52 53 54 55 56 57 58 59 60 61 62 63
pub async fn serve<B>(self, request: Request<B>) -> Result<Response<Body>, IoError> {
let Self {
root,
cache_headers,
} = self;
resolve(root, &request).await.map(|result| {
ResponseBuilder::new()
.request(&request)
.cache_headers(cache_headers)
.build(result)
.expect("unable to build response")
})
}
Trait Implementations§
source§impl<'a> Clone for ResponseBuilder<'a>
impl<'a> Clone for ResponseBuilder<'a>
source§fn clone(&self) -> ResponseBuilder<'a>
fn clone(&self) -> ResponseBuilder<'a>
Returns a copy 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 moresource§impl<'a> Debug for ResponseBuilder<'a>
impl<'a> Debug for ResponseBuilder<'a>
source§impl<'a> Default for ResponseBuilder<'a>
impl<'a> Default for ResponseBuilder<'a>
source§fn default() -> ResponseBuilder<'a>
fn default() -> ResponseBuilder<'a>
Returns the “default value” for a type. Read more