/// 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.
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.
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 .
pub fn build(&self, result: ResolveResult) -> Result<Response<Body>> {
        match result {
            ResolveResult::MethodNotMatched => HttpResponseBuilder::new()
                .status(StatusCode::BAD_REQUEST)
                .body(Body::empty()),
            ResolveResult::UriNotMatched | ResolveResult::NotFound => HttpResponseBuilder::new()
                .status(StatusCode::NOT_FOUND)
                .body(Body::empty()),
            ResolveResult::PermissionDenied => HttpResponseBuilder::new()
                .status(StatusCode::FORBIDDEN)
                .body(Body::empty()),
            ResolveResult::IsDirectory => {
                let mut target = self.path.to_owned();
                target.push('/');
                if let Some(query) = self.query {
                    target.push('?');
                    target.push_str(query);
                }
                HttpResponseBuilder::new()
                    .status(StatusCode::MOVED_PERMANENTLY)
                    .header(header::LOCATION, target)
                    .body(Body::empty())
            }
            ResolveResult::Found(file, metadata, mime) => {
                self.file_response_builder
                    .build(file, metadata, mime.to_string())
            }
        }
    }
pub fn build ( & self , result : ResolveResult ) -> Result < Response < Body > > { match result { ResolveResult :: MethodNotMatched => HttpResponseBuilder :: new ( ) . status ( StatusCode :: BAD_REQUEST ) . body ( Body :: empty ( ) ) , ResolveResult :: UriNotMatched | ResolveResult :: NotFound => HttpResponseBuilder :: new ( ) . status ( StatusCode :: NOT_FOUND ) . body ( Body :: empty ( ) ) , ResolveResult :: PermissionDenied => HttpResponseBuilder :: new ( ) . status ( StatusCode :: FORBIDDEN ) . body ( Body :: empty ( ) ) , ResolveResult :: IsDirectory => { let mut target = self . path . to_owned ( ) ; target . push ( '/' ) ; if let Some ( query ) = self . query { target . push ( '?' ) ; target . push_str ( query ) ; } HttpResponseBuilder :: new ( ) . status ( StatusCode :: MOVED_PERMANENTLY ) . header ( header :: LOCATION , target ) . body ( Body :: empty ( ) ) } ResolveResult :: Found ( file , metadata , mime ) => { self . file_response_builder . build ( file , metadata , mime . to_string ( ) ) } } }
Build a response for the given request and `resolve` result.
Build a response for the given request and ` resolve ` result .
&self
result
ResolveResult