Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dowwie authored Apr 18, 2019
2 parents da86b6e + aa25529 commit ed94df1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

* Rename `test::call_success` to `test::call_service`

* Removed `ServiceRequest::from_parts()` as it is unsafe to create from parts.

### Fixed

* Fixed `TestRequest::app_data()`
Expand Down
32 changes: 16 additions & 16 deletions actix-files/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,16 @@ impl FilesService {
fn handle_err(
&mut self,
e: io::Error,
req: HttpRequest,
payload: Payload,
req: ServiceRequest,
) -> Either<
FutureResult<ServiceResponse, Error>,
Box<Future<Item = ServiceResponse, Error = Error>>,
> {
log::debug!("Files: Failed to handle {}: {}", req.path(), e);
if let Some(ref mut default) = self.default {
default.call(ServiceRequest::from_parts(req, payload))
default.call(req)
} else {
Either::A(ok(ServiceResponse::from_err(e, req.clone())))
Either::A(ok(req.error_response(e)))
}
}
}
Expand All @@ -440,17 +439,17 @@ impl Service for FilesService {
}

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()) {
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
let path = match self.directory.join(&real_path.0).canonicalize() {
Ok(path) => path,
Err(e) => return self.handle_err(e, req, pl),
Err(e) => return self.handle_err(e, req),
};

if path.is_dir() {
Expand All @@ -466,24 +465,26 @@ impl Service for FilesService {
}

named_file.flags = self.file_flags;
let (req, _) = req.into_parts();
Either::A(ok(match named_file.respond_to(&req) {
Ok(item) => ServiceResponse::new(req.clone(), item),
Err(e) => ServiceResponse::from_err(e, req.clone()),
Ok(item) => ServiceResponse::new(req, item),
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 {
let dir = Directory::new(self.directory.clone(), path);
let (req, _) = req.into_parts();
let x = (self.renderer)(&dir, &req);
match x {
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 {
Either::A(ok(ServiceResponse::from_err(
FilesError::IsDirectory,
req.clone(),
req.into_parts().0,
)))
}
} else {
Expand All @@ -496,16 +497,15 @@ impl Service for FilesService {
}

named_file.flags = self.file_flags;
let (req, _) = req.into_parts();
match named_file.respond_to(&req) {
Ok(item) => {
Either::A(ok(ServiceResponse::new(req.clone(), item)))
}
Err(e) => {
Either::A(ok(ServiceResponse::from_err(e, req.clone())))
}
Err(e) => Either::A(ok(ServiceResponse::from_err(e, req))),
}
}
Err(e) => self.handle_err(e, req, pl),
Err(e) => self.handle_err(e, req),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct ServiceRequest {

impl ServiceRequest {
/// 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 }
}

Expand Down

0 comments on commit ed94df1

Please sign in to comment.