mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
make ServiceRequest::from_parts private, as it is not safe to create from parts
This commit is contained in:
parent
75e340137d
commit
aa255298ef
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
* Rename `test::call_success` to `test::call_service`
|
* Rename `test::call_success` to `test::call_service`
|
||||||
|
|
||||||
|
* Removed `ServiceRequest::from_parts()` as it is unsafe to create from parts.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Fixed `TestRequest::app_data()`
|
* Fixed `TestRequest::app_data()`
|
||||||
|
@ -411,17 +411,16 @@ impl FilesService {
|
|||||||
fn handle_err(
|
fn handle_err(
|
||||||
&mut self,
|
&mut self,
|
||||||
e: io::Error,
|
e: io::Error,
|
||||||
req: HttpRequest,
|
req: ServiceRequest,
|
||||||
payload: Payload,
|
|
||||||
) -> Either<
|
) -> Either<
|
||||||
FutureResult<ServiceResponse, Error>,
|
FutureResult<ServiceResponse, Error>,
|
||||||
Box<Future<Item = ServiceResponse, Error = Error>>,
|
Box<Future<Item = ServiceResponse, Error = Error>>,
|
||||||
> {
|
> {
|
||||||
log::debug!("Files: Failed to handle {}: {}", req.path(), e);
|
log::debug!("Files: Failed to handle {}: {}", req.path(), e);
|
||||||
if let Some(ref mut default) = self.default {
|
if let Some(ref mut default) = self.default {
|
||||||
default.call(ServiceRequest::from_parts(req, payload))
|
default.call(req)
|
||||||
} else {
|
} else {
|
||||||
Either::A(ok(ServiceResponse::from_err(e, req.clone())))
|
Either::A(ok(req.error_response(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,17 +439,17 @@ impl Service for FilesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||||
let (req, pl) = req.into_parts();
|
// let (req, pl) = req.into_parts();
|
||||||
|
|
||||||
let real_path = match PathBufWrp::get_pathbuf(req.match_info().path()) {
|
let real_path = match PathBufWrp::get_pathbuf(req.match_info().path()) {
|
||||||
Ok(item) => item,
|
Ok(item) => item,
|
||||||
Err(e) => return Either::A(ok(ServiceResponse::from_err(e, req.clone()))),
|
Err(e) => return Either::A(ok(req.error_response(e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
// full filepath
|
// full filepath
|
||||||
let path = match self.directory.join(&real_path.0).canonicalize() {
|
let path = match self.directory.join(&real_path.0).canonicalize() {
|
||||||
Ok(path) => path,
|
Ok(path) => path,
|
||||||
Err(e) => return self.handle_err(e, req, pl),
|
Err(e) => return self.handle_err(e, req),
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
@ -466,24 +465,26 @@ impl Service for FilesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
named_file.flags = self.file_flags;
|
named_file.flags = self.file_flags;
|
||||||
|
let (req, _) = req.into_parts();
|
||||||
Either::A(ok(match named_file.respond_to(&req) {
|
Either::A(ok(match named_file.respond_to(&req) {
|
||||||
Ok(item) => ServiceResponse::new(req.clone(), item),
|
Ok(item) => ServiceResponse::new(req, item),
|
||||||
Err(e) => ServiceResponse::from_err(e, req.clone()),
|
Err(e) => ServiceResponse::from_err(e, req),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
Err(e) => return self.handle_err(e, req, pl),
|
Err(e) => return self.handle_err(e, req),
|
||||||
}
|
}
|
||||||
} else if self.show_index {
|
} else if self.show_index {
|
||||||
let dir = Directory::new(self.directory.clone(), path);
|
let dir = Directory::new(self.directory.clone(), path);
|
||||||
|
let (req, _) = req.into_parts();
|
||||||
let x = (self.renderer)(&dir, &req);
|
let x = (self.renderer)(&dir, &req);
|
||||||
match x {
|
match x {
|
||||||
Ok(resp) => Either::A(ok(resp)),
|
Ok(resp) => Either::A(ok(resp)),
|
||||||
Err(e) => return self.handle_err(e, req, pl),
|
Err(e) => return Either::A(ok(ServiceResponse::from_err(e, req))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Either::A(ok(ServiceResponse::from_err(
|
Either::A(ok(ServiceResponse::from_err(
|
||||||
FilesError::IsDirectory,
|
FilesError::IsDirectory,
|
||||||
req.clone(),
|
req.into_parts().0,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -496,16 +497,15 @@ impl Service for FilesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
named_file.flags = self.file_flags;
|
named_file.flags = self.file_flags;
|
||||||
|
let (req, _) = req.into_parts();
|
||||||
match named_file.respond_to(&req) {
|
match named_file.respond_to(&req) {
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
Either::A(ok(ServiceResponse::new(req.clone(), item)))
|
Either::A(ok(ServiceResponse::new(req.clone(), item)))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => Either::A(ok(ServiceResponse::from_err(e, req))),
|
||||||
Either::A(ok(ServiceResponse::from_err(e, req.clone())))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(e) => self.handle_err(e, req),
|
||||||
Err(e) => self.handle_err(e, req, pl),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ pub struct ServiceRequest {
|
|||||||
|
|
||||||
impl ServiceRequest {
|
impl ServiceRequest {
|
||||||
/// Construct service request from parts
|
/// Construct service request from parts
|
||||||
pub fn from_parts(req: HttpRequest, payload: Payload) -> Self {
|
pub(crate) fn from_parts(req: HttpRequest, payload: Payload) -> Self {
|
||||||
ServiceRequest { req, payload }
|
ServiceRequest { req, payload }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user