mirror of
https://github.com/actix/actix-web.git
synced 2024-12-22 08:07:18 +00:00
minor syntax changes
This commit is contained in:
parent
fee203b402
commit
aee24d4af0
1 changed files with 11 additions and 12 deletions
23
src/fs.rs
23
src/fs.rs
|
@ -68,8 +68,7 @@ impl NamedFile {
|
||||||
|
|
||||||
// Get the name of the file and use it to construct default Content-Type
|
// Get the name of the file and use it to construct default Content-Type
|
||||||
// and Content-Disposition values
|
// and Content-Disposition values
|
||||||
let content_type;
|
let (content_type, content_disposition) =
|
||||||
let content_disposition;
|
|
||||||
{
|
{
|
||||||
let filename = match path.file_name() {
|
let filename = match path.file_name() {
|
||||||
Some(name) => name.to_string_lossy(),
|
Some(name) => name.to_string_lossy(),
|
||||||
|
@ -78,12 +77,12 @@ impl NamedFile {
|
||||||
"Provided path has no filename")),
|
"Provided path has no filename")),
|
||||||
};
|
};
|
||||||
|
|
||||||
content_type = guess_mime_type(&path);
|
let ct = guess_mime_type(&path);
|
||||||
let disposition_type = match content_type.type_() {
|
let disposition_type = match ct.type_() {
|
||||||
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
|
mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
|
||||||
_ => DispositionType::Attachment,
|
_ => DispositionType::Attachment,
|
||||||
};
|
};
|
||||||
content_disposition = ContentDisposition {
|
let cd = ContentDisposition {
|
||||||
disposition: disposition_type,
|
disposition: disposition_type,
|
||||||
parameters: vec![
|
parameters: vec![
|
||||||
DispositionParam::Filename(
|
DispositionParam::Filename(
|
||||||
|
@ -93,7 +92,8 @@ impl NamedFile {
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
(ct, cd)
|
||||||
|
};
|
||||||
|
|
||||||
let file = File::open(&path)?;
|
let file = File::open(&path)?;
|
||||||
let md = file.metadata()?;
|
let md = file.metadata()?;
|
||||||
|
@ -275,9 +275,8 @@ impl Responder for NamedFile {
|
||||||
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, io::Error> {
|
fn respond_to<S>(self, req: &HttpRequest<S>) -> Result<HttpResponse, io::Error> {
|
||||||
if self.status_code != StatusCode::OK {
|
if self.status_code != StatusCode::OK {
|
||||||
let mut resp = HttpResponse::build(self.status_code);
|
let mut resp = HttpResponse::build(self.status_code);
|
||||||
|
resp.set(header::ContentType(self.content_type.clone()))
|
||||||
resp.set(header::ContentType(self.content_type.clone()));
|
.header("Content-Disposition", format!("{}", &self.content_disposition));
|
||||||
resp.header("Content-Disposition", format!("{}", &self.content_disposition));
|
|
||||||
|
|
||||||
if let Some(current_encoding) = self.encoding {
|
if let Some(current_encoding) = self.encoding {
|
||||||
resp.content_encoding(current_encoding);
|
resp.content_encoding(current_encoding);
|
||||||
|
@ -327,13 +326,13 @@ impl Responder for NamedFile {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut resp = HttpResponse::build(self.status_code);
|
let mut resp = HttpResponse::build(self.status_code);
|
||||||
|
resp.set(header::ContentType(self.content_type.clone()))
|
||||||
|
.header("Content-Disposition", format!("{}", &self.content_disposition));
|
||||||
|
|
||||||
if let Some(current_encoding) = self.encoding {
|
if let Some(current_encoding) = self.encoding {
|
||||||
resp.content_encoding(current_encoding);
|
resp.content_encoding(current_encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.set(header::ContentType(self.content_type.clone()));
|
|
||||||
resp.header("Content-Disposition", format!("{}", &self.content_disposition));
|
|
||||||
|
|
||||||
resp
|
resp
|
||||||
.if_some(last_modified, |lm, resp| {
|
.if_some(last_modified, |lm, resp| {
|
||||||
resp.set(header::LastModified(lm));
|
resp.set(header::LastModified(lm));
|
||||||
|
|
Loading…
Reference in a new issue