From 4862227df9227f87ca2aa0565220778d2ac72c7e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 21 Jul 2018 05:58:08 -0700 Subject: [PATCH] fix not implemented panic #410 --- CHANGES.md | 7 +++++++ Cargo.toml | 2 +- src/application.rs | 2 ++ src/fs.rs | 47 +++++++++++++++++++++++++--------------------- src/handler.rs | 4 +--- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7564a5597..d83736eb5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.7.1] - 2018-07-21 + +### Fixed + +* Fixed default_resource 'not yet implemented' panic #410 + + ## [0.7.0] - 2018-07-21 ### Added diff --git a/Cargo.toml b/Cargo.toml index 1d6b1663a..a6b73ee55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "0.7.0" +version = "0.7.1" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" diff --git a/src/application.rs b/src/application.rs index ebf441ec7..72ecff3da 100644 --- a/src/application.rs +++ b/src/application.rs @@ -610,6 +610,7 @@ impl Iterator for App { mod tests { use super::*; use body::{Binary, Body}; + use fs; use http::StatusCode; use httprequest::HttpRequest; use httpresponse::HttpResponse; @@ -631,6 +632,7 @@ mod tests { assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND); let app = App::new() + .resource("/test", |r| r.f(|_| HttpResponse::Ok())) .default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed())) .finish(); let req = TestRequest::with_uri("/blah").request(); diff --git a/src/fs.rs b/src/fs.rs index 31b3725b4..f23ba12cd 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -2,11 +2,11 @@ use std::fmt::Write; use std::fs::{DirEntry, File, Metadata}; use std::io::{Read, Seek}; +use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; use std::time::{SystemTime, UNIX_EPOCH}; use std::{cmp, io}; -use std::marker::PhantomData; #[cfg(unix)] use std::os::unix::fs::MetadataExt; @@ -22,13 +22,13 @@ use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use error::{Error, StaticFileError}; use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler}; use header; +use header::{ContentDisposition, DispositionParam, DispositionType}; use http::{ContentEncoding, Method, StatusCode}; use httpmessage::HttpMessage; use httprequest::HttpRequest; use httpresponse::HttpResponse; use param::FromParam; use server::settings::DEFAULT_CPUPOOL; -use header::{ContentDisposition, DispositionParam, DispositionType}; ///Describes `StaticFiles` configiration /// @@ -106,7 +106,7 @@ pub fn file_extension_to_mime(ext: &str) -> mime::Mime { /// A file with an associated name. #[derive(Debug)] -pub struct NamedFile { +pub struct NamedFile { path: PathBuf, file: File, content_type: mime::Mime, @@ -188,7 +188,7 @@ impl NamedFile { cpu_pool, encoding, status_code: StatusCode::OK, - _cd_map: PhantomData + _cd_map: PhantomData, }) } @@ -366,21 +366,22 @@ impl Responder for NamedFile { return Ok(resp.streaming(reader)); } - if !C::is_method_allowed(req.method()) - { + if !C::is_method_allowed(req.method()) { return Ok(HttpResponse::MethodNotAllowed() .header(header::CONTENT_TYPE, "text/plain") .header(header::ALLOW, "GET, HEAD") .body("This resource only supports GET and HEAD.")); } - let etag = match C::is_use_etag() { - true => self.etag(), - false => None, + let etag = if C::is_use_etag() { + self.etag() + } else { + None }; - let last_modified = match C::is_use_last_modifier() { - true => self.last_modified(), - false => None, + let last_modified = if C::is_use_last_modifier() { + self.last_modified() + } else { + None }; // check preconditions @@ -637,7 +638,7 @@ fn directory_listing( /// .finish(); /// } /// ``` -pub struct StaticFiles { +pub struct StaticFiles { directory: PathBuf, index: Option, show_index: bool, @@ -672,7 +673,9 @@ impl StaticFiles { /// Create new `StaticFiles` instance for specified base directory. /// /// Identical with `new` but allows to specify configiration to use. - pub fn with_config>(dir: T, config: C) -> Result, Error> { + pub fn with_config>( + dir: T, config: C, + ) -> Result, Error> { // use default CpuPool let pool = { DEFAULT_CPUPOOL.lock().clone() }; @@ -682,7 +685,7 @@ impl StaticFiles { /// Create new `StaticFiles` instance for specified base directory with config and /// `CpuPool`. pub fn with_config_pool>( - dir: T, pool: CpuPool, _: C + dir: T, pool: CpuPool, _: C, ) -> Result, Error> { let dir = dir.into().canonicalize()?; @@ -701,7 +704,7 @@ impl StaticFiles { renderer: Box::new(directory_listing), _chunk_size: 0, _follow_symlinks: false, - _cd_map: PhantomData + _cd_map: PhantomData, }) } @@ -1064,7 +1067,6 @@ mod tests { resp.headers().get(header::CONTENT_DISPOSITION).unwrap(), "inline; filename=\"test.png\"" ); - } #[test] @@ -1296,24 +1298,27 @@ mod tests { fn is_method_allowed(method: &Method) -> bool { match *method { Method::HEAD => true, - _ => false + _ => false, } } } #[test] fn test_named_file_not_allowed() { - let file = NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); + let file = + NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); let req = TestRequest::default().method(Method::POST).finish(); let resp = file.respond_to(&req).unwrap(); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); - let file = NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); + let file = + NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); let req = TestRequest::default().method(Method::PUT).finish(); let resp = file.respond_to(&req).unwrap(); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); - let file = NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); + let file = + NamedFile::open_with_config("Cargo.toml", OnlyMethodHeadConfig).unwrap(); let req = TestRequest::default().method(Method::GET).finish(); let resp = file.respond_to(&req).unwrap(); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); diff --git a/src/handler.rs b/src/handler.rs index 98d253438..3ac0c2ab2 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -408,9 +408,7 @@ pub(crate) trait RouteHandler: 'static { false } - fn default_resource(&mut self, _: DefaultResource) { - unimplemented!() - } + fn default_resource(&mut self, _: DefaultResource) {} fn finish(&mut self) {} }