diff options
author | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-08 22:57:05 +0000 |
---|---|---|
committer | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-08 22:57:05 +0000 |
commit | 46932e7d5664c97ad65aefc3f670f7e64e6f8e0d (patch) | |
tree | 3fc24f42bca31fc0d901520e1f111c656904e50c /src | |
parent | Corrected comment (diff) | |
download | miniserve-46932e7d5664c97ad65aefc3f670f7e64e6f8e0d.tar.gz miniserve-46932e7d5664c97ad65aefc3f670f7e64e6f8e0d.zip |
Improved HTTP headers
Diffstat (limited to 'src')
-rw-r--r-- | src/archive.rs | 14 | ||||
-rw-r--r-- | src/listing.rs | 3 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/archive.rs b/src/archive.rs index 0f09005..1b31d08 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,3 +1,4 @@ +use actix_web::http::ContentEncoding; use bytes::Bytes; use libflate::gzip::Encoder; use serde::Deserialize; @@ -29,6 +30,19 @@ impl CompressionMethod { } .to_string() } + + pub fn content_type(&self) -> String { + match &self { + CompressionMethod::TarGz => "application/gzip", + } + .to_string() + } + + pub fn content_encoding(&self) -> ContentEncoding { + match &self { + CompressionMethod::TarGz => ContentEncoding::Gzip, + } + } } /// Possible errors diff --git a/src/listing.rs b/src/listing.rs index c9542b8..f7198a5 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -230,8 +230,9 @@ pub fn directory_listing<S>( if let Some(compression_method) = &download { match archive::create_archive_file(&compression_method, &dir.path) { Ok((filename, content)) => Ok(HttpResponse::Ok() - .content_type("application/tar") + .content_type(compression_method.content_type()) .content_length(content.len() as u64) + .content_encoding(compression_method.content_encoding()) .header("Content-Transfer-Encoding", "binary") .header( "Content-Disposition", |