fn serve_sync(&self, path: &str, can_gzip: bool) -> Result<Response, Error> {
        let mut response = Response::new();
        match path {
            "/reloadTemplates" => {
                self.reload_templates()?;
                response.set_status(StatusCode::Ok);
                response.headers_mut().set(ContentType::plaintext());
                response.set_body("reloaded");
            }
            "/sync" => {
                response.set_status(StatusCode::Ok);
                response.headers_mut().set(ContentType::plaintext());
                response.set_body("synchronization request sent, go back and refresh.");
            }
            _ => {
                response.set_status(StatusCode::NotFound);
                if SAFE_PATH_RE.is_match(path.as_bytes()) {
                    let path = self.args.templates.join(&path[1..]);
                    if path.exists() {
                        let mime = path
                            .extension()
                            .and_then(OsStr::to_str)
                            .and_then(|ext| KNOWN_CONTENT_TYPES.get(ext));

                        response.set_status(StatusCode::Ok);
                        {
                            let headers = response.headers_mut();
                            headers.set(CacheControl(vec![Public, MaxAge(31_536_000)]));
                            if let Some(mime) = mime {
                                headers.set(ContentType(mime.clone()));
                            }
                        }

                        let file = File::open(path)?;
                        set_response_body(&mut response, file, can_gzip)?;
                    }
                }
            }
        }
        Ok(response)
    }
/// Serves a response which doesn't require asynchronous requests.
Serves a response which doesn't require asynchronous requests.
Serves a response which doesn ' t require asynchronous requests .
fn serve_sync(&self, path: &str, can_gzip: bool) -> Result<Response, Error> {
        let mut response = Response::new();
        match path {
            "/reloadTemplates" => {
                self.reload_templates()?;
                response.set_status(StatusCode::Ok);
                response.headers_mut().set(ContentType::plaintext());
                response.set_body("reloaded");
            }
            "/sync" => {
                response.set_status(StatusCode::Ok);
                response.headers_mut().set(ContentType::plaintext());
                response.set_body("synchronization request sent, go back and refresh.");
            }
            _ => {
                response.set_status(StatusCode::NotFound);
                if SAFE_PATH_RE.is_match(path.as_bytes()) {
                    let path = self.args.templates.join(&path[1..]);
                    if path.exists() {
                        let mime = path
                            .extension()
                            .and_then(OsStr::to_str)
                            .and_then(|ext| KNOWN_CONTENT_TYPES.get(ext));
                        response.set_status(StatusCode::Ok);
                        {
                            let headers = response.headers_mut();
                            headers.set(CacheControl(vec![Public, MaxAge(31_536_000)]));
                            if let Some(mime) = mime {
                                headers.set(ContentType(mime.clone()));
                            }
                        }
                        let file = File::open(path)?;
                        set_response_body(&mut response, file, can_gzip)?;
                    }
                }
            }
        }
        Ok(response)
    }
fn serve_sync ( & self , path : & str , can_gzip : bool ) -> Result < Response , Error > { let mut response = Response :: new ( ) ; match path { " " => { self . reload_templates ( ) ? ; response . set_status ( StatusCode :: Ok ) ; response . headers_mut ( ) . set ( ContentType :: plaintext ( ) ) ; response . set_body ( " " ) ; } " " => { response . set_status ( StatusCode :: Ok ) ; response . headers_mut ( ) . set ( ContentType :: plaintext ( ) ) ; response . set_body ( " " ) ; } _ => { response . set_status ( StatusCode :: NotFound ) ; if SAFE_PATH_RE . is_match ( path . as_bytes ( ) ) { let path = self . args . templates . join ( & path [ 1 .. ] ) ; if path . exists ( ) { let mime = path . extension ( ) . and_then ( OsStr :: to_str ) . and_then ( | ext | KNOWN_CONTENT_TYPES . get ( ext ) ) ; response . set_status ( StatusCode :: Ok ) ; { let headers = response . headers_mut ( ) ; headers . set ( CacheControl ( vec ! [ Public MaxAge ( 31_536_000 ) ] ) ) ; if let Some ( mime ) = mime { headers . set ( ContentType ( mime . clone ( ) ) ) ; } } let file = File :: open ( path ) ? ; set_response_body ( & mut response , file , can_gzip ) ? ; } } } } Ok ( response ) }
Serves a response which doesn't require asynchronous requests.
Serves a response which doesn ' t require asynchronous requests .
&self
path
&str
can_gzip
bool
&self
path
&str
can_gzip
bool