mirror of https://github.com/fafhrd91/actix-web
refactor for more flat code
This commit is contained in:
parent
e5b713b04a
commit
11b56d6c6f
|
@ -102,26 +102,20 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref redir_index) = self.index {
|
let serve_named_file = |req: ServiceRequest, mut named_file: NamedFile| {
|
||||||
let path = path.join(redir_index);
|
if let Some(ref mime_override) = self.mime_override {
|
||||||
|
let new_disposition = mime_override(&named_file.content_type.type_());
|
||||||
match NamedFile::open(path) {
|
named_file.content_disposition.disposition = new_disposition;
|
||||||
Ok(mut named_file) => {
|
|
||||||
if let Some(ref mime_override) = self.mime_override {
|
|
||||||
let new_disposition =
|
|
||||||
mime_override(&named_file.content_type.type_());
|
|
||||||
named_file.content_disposition.disposition = new_disposition;
|
|
||||||
}
|
|
||||||
named_file.flags = self.file_flags;
|
|
||||||
|
|
||||||
let (req, _) = req.into_parts();
|
|
||||||
let res = named_file.into_response(&req);
|
|
||||||
Box::pin(ok(ServiceResponse::new(req, res)))
|
|
||||||
}
|
|
||||||
Err(err) => self.handle_err(err, req),
|
|
||||||
}
|
}
|
||||||
} else if self.show_index {
|
named_file.flags = self.file_flags;
|
||||||
let dir = Directory::new(self.directory.clone(), path);
|
|
||||||
|
let (req, _) = req.into_parts();
|
||||||
|
let res = named_file.into_response(&req);
|
||||||
|
Box::pin(ok(ServiceResponse::new(req, res)))
|
||||||
|
};
|
||||||
|
|
||||||
|
let show_index = |req: ServiceRequest| {
|
||||||
|
let dir = Directory::new(self.directory.clone(), path.clone());
|
||||||
|
|
||||||
let (req, _) = req.into_parts();
|
let (req, _) = req.into_parts();
|
||||||
let x = (self.renderer)(&dir, &req);
|
let x = (self.renderer)(&dir, &req);
|
||||||
|
@ -130,11 +124,18 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
Ok(resp) => ok(resp),
|
Ok(resp) => ok(resp),
|
||||||
Err(err) => ok(ServiceResponse::from_err(err, req)),
|
Err(err) => ok(ServiceResponse::from_err(err, req)),
|
||||||
})
|
})
|
||||||
} else {
|
};
|
||||||
Box::pin(ok(ServiceResponse::from_err(
|
|
||||||
|
match self.index {
|
||||||
|
Some(ref index) => match NamedFile::open(path.join(index)) {
|
||||||
|
Ok(named_file) => serve_named_file(req, named_file),
|
||||||
|
Err(err) => self.handle_err(err, req),
|
||||||
|
},
|
||||||
|
None if self.show_index => show_index(req),
|
||||||
|
_ => Box::pin(ok(ServiceResponse::from_err(
|
||||||
FilesError::IsDirectory,
|
FilesError::IsDirectory,
|
||||||
req.into_parts().0,
|
req.into_parts().0,
|
||||||
)))
|
))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match NamedFile::open(path) {
|
match NamedFile::open(path) {
|
||||||
|
|
Loading…
Reference in New Issue