mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
fix not implemented panic #410
This commit is contained in:
parent
f6499d9ba5
commit
4862227df9
@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.7.1] - 2018-07-21
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Fixed default_resource 'not yet implemented' panic #410
|
||||||
|
|
||||||
|
|
||||||
## [0.7.0] - 2018-07-21
|
## [0.7.0] - 2018-07-21
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
|
description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -610,6 +610,7 @@ impl<S: 'static> Iterator for App<S> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use body::{Binary, Body};
|
use body::{Binary, Body};
|
||||||
|
use fs;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
@ -631,6 +632,7 @@ mod tests {
|
|||||||
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
assert_eq!(resp.as_msg().status(), StatusCode::NOT_FOUND);
|
||||||
|
|
||||||
let app = App::new()
|
let app = App::new()
|
||||||
|
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed()))
|
.default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed()))
|
||||||
.finish();
|
.finish();
|
||||||
let req = TestRequest::with_uri("/blah").request();
|
let req = TestRequest::with_uri("/blah").request();
|
||||||
|
43
src/fs.rs
43
src/fs.rs
@ -2,11 +2,11 @@
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::fs::{DirEntry, File, Metadata};
|
use std::fs::{DirEntry, File, Metadata};
|
||||||
use std::io::{Read, Seek};
|
use std::io::{Read, Seek};
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use std::{cmp, io};
|
use std::{cmp, io};
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
@ -22,13 +22,13 @@ use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
|
|||||||
use error::{Error, StaticFileError};
|
use error::{Error, StaticFileError};
|
||||||
use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler};
|
use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler};
|
||||||
use header;
|
use header;
|
||||||
|
use header::{ContentDisposition, DispositionParam, DispositionType};
|
||||||
use http::{ContentEncoding, Method, StatusCode};
|
use http::{ContentEncoding, Method, StatusCode};
|
||||||
use httpmessage::HttpMessage;
|
use httpmessage::HttpMessage;
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use httpresponse::HttpResponse;
|
use httpresponse::HttpResponse;
|
||||||
use param::FromParam;
|
use param::FromParam;
|
||||||
use server::settings::DEFAULT_CPUPOOL;
|
use server::settings::DEFAULT_CPUPOOL;
|
||||||
use header::{ContentDisposition, DispositionParam, DispositionType};
|
|
||||||
|
|
||||||
///Describes `StaticFiles` configiration
|
///Describes `StaticFiles` configiration
|
||||||
///
|
///
|
||||||
@ -188,7 +188,7 @@ impl<C: StaticFileConfig> NamedFile<C> {
|
|||||||
cpu_pool,
|
cpu_pool,
|
||||||
encoding,
|
encoding,
|
||||||
status_code: StatusCode::OK,
|
status_code: StatusCode::OK,
|
||||||
_cd_map: PhantomData
|
_cd_map: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,21 +366,22 @@ impl<C: StaticFileConfig> Responder for NamedFile<C> {
|
|||||||
return Ok(resp.streaming(reader));
|
return Ok(resp.streaming(reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !C::is_method_allowed(req.method())
|
if !C::is_method_allowed(req.method()) {
|
||||||
{
|
|
||||||
return Ok(HttpResponse::MethodNotAllowed()
|
return Ok(HttpResponse::MethodNotAllowed()
|
||||||
.header(header::CONTENT_TYPE, "text/plain")
|
.header(header::CONTENT_TYPE, "text/plain")
|
||||||
.header(header::ALLOW, "GET, HEAD")
|
.header(header::ALLOW, "GET, HEAD")
|
||||||
.body("This resource only supports GET and HEAD."));
|
.body("This resource only supports GET and HEAD."));
|
||||||
}
|
}
|
||||||
|
|
||||||
let etag = match C::is_use_etag() {
|
let etag = if C::is_use_etag() {
|
||||||
true => self.etag(),
|
self.etag()
|
||||||
false => None,
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
let last_modified = match C::is_use_last_modifier() {
|
let last_modified = if C::is_use_last_modifier() {
|
||||||
true => self.last_modified(),
|
self.last_modified()
|
||||||
false => None,
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
// check preconditions
|
// check preconditions
|
||||||
@ -672,7 +673,9 @@ impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C> {
|
|||||||
/// Create new `StaticFiles` instance for specified base directory.
|
/// Create new `StaticFiles` instance for specified base directory.
|
||||||
///
|
///
|
||||||
/// Identical with `new` but allows to specify configiration to use.
|
/// Identical with `new` but allows to specify configiration to use.
|
||||||
pub fn with_config<T: Into<PathBuf>>(dir: T, config: C) -> Result<StaticFiles<S, C>, Error> {
|
pub fn with_config<T: Into<PathBuf>>(
|
||||||
|
dir: T, config: C,
|
||||||
|
) -> Result<StaticFiles<S, C>, Error> {
|
||||||
// use default CpuPool
|
// use default CpuPool
|
||||||
let pool = { DEFAULT_CPUPOOL.lock().clone() };
|
let pool = { DEFAULT_CPUPOOL.lock().clone() };
|
||||||
|
|
||||||
@ -682,7 +685,7 @@ impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C> {
|
|||||||
/// Create new `StaticFiles` instance for specified base directory with config and
|
/// Create new `StaticFiles` instance for specified base directory with config and
|
||||||
/// `CpuPool`.
|
/// `CpuPool`.
|
||||||
pub fn with_config_pool<T: Into<PathBuf>>(
|
pub fn with_config_pool<T: Into<PathBuf>>(
|
||||||
dir: T, pool: CpuPool, _: C
|
dir: T, pool: CpuPool, _: C,
|
||||||
) -> Result<StaticFiles<S, C>, Error> {
|
) -> Result<StaticFiles<S, C>, Error> {
|
||||||
let dir = dir.into().canonicalize()?;
|
let dir = dir.into().canonicalize()?;
|
||||||
|
|
||||||
@ -701,7 +704,7 @@ impl<S: 'static, C: StaticFileConfig> StaticFiles<S, C> {
|
|||||||
renderer: Box::new(directory_listing),
|
renderer: Box::new(directory_listing),
|
||||||
_chunk_size: 0,
|
_chunk_size: 0,
|
||||||
_follow_symlinks: false,
|
_follow_symlinks: false,
|
||||||
_cd_map: PhantomData
|
_cd_map: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1064,7 +1067,6 @@ mod tests {
|
|||||||
resp.headers().get(header::CONTENT_DISPOSITION).unwrap(),
|
resp.headers().get(header::CONTENT_DISPOSITION).unwrap(),
|
||||||
"inline; filename=\"test.png\""
|
"inline; filename=\"test.png\""
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1296,24 +1298,27 @@ mod tests {
|
|||||||
fn is_method_allowed(method: &Method) -> bool {
|
fn is_method_allowed(method: &Method) -> bool {
|
||||||
match *method {
|
match *method {
|
||||||
Method::HEAD => true,
|
Method::HEAD => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_named_file_not_allowed() {
|
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 req = TestRequest::default().method(Method::POST).finish();
|
||||||
let resp = file.respond_to(&req).unwrap();
|
let resp = file.respond_to(&req).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
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 req = TestRequest::default().method(Method::PUT).finish();
|
||||||
let resp = file.respond_to(&req).unwrap();
|
let resp = file.respond_to(&req).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
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 req = TestRequest::default().method(Method::GET).finish();
|
||||||
let resp = file.respond_to(&req).unwrap();
|
let resp = file.respond_to(&req).unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
|
||||||
|
@ -408,9 +408,7 @@ pub(crate) trait RouteHandler<S>: 'static {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_resource(&mut self, _: DefaultResource<S>) {
|
fn default_resource(&mut self, _: DefaultResource<S>) {}
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finish(&mut self) {}
|
fn finish(&mut self) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user