aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_put.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-07-09 17:04:43 +0200
committerAlex Auvolat <alex@adnab.me>2020-07-09 17:04:43 +0200
commit9305e5e87f947172984f60742c1d96d42acb5950 (patch)
treead5f94d5c4c07c3b5d239942379fc1a1bf750467 /src/api/s3_put.rs
parent44dba0e53c7bae0fa16bf48e6022faa95d1159aa (diff)
downloadgarage-9305e5e87f947172984f60742c1d96d42acb5950.tar.gz
garage-9305e5e87f947172984f60742c1d96d42acb5950.zip
More headers taken into account
Diffstat (limited to 'src/api/s3_put.rs')
-rw-r--r--src/api/s3_put.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs
index 9ac7dafd..0a010a82 100644
--- a/src/api/s3_put.rs
+++ b/src/api/s3_put.rs
@@ -24,10 +24,7 @@ pub async fn handle_put(
key: &str,
) -> Result<Response<Body>, Error> {
let version_uuid = gen_uuid();
- let headers = ObjectVersionHeaders {
- content_type: get_mime_type(&req)?,
- other: BTreeMap::new(), // TODO
- };
+ let headers = get_headers(&req)?;
let body = req.into_body();
@@ -221,10 +218,7 @@ pub async fn handle_create_multipart_upload(
key: &str,
) -> Result<Response<Body>, Error> {
let version_uuid = gen_uuid();
- let headers = ObjectVersionHeaders {
- content_type: get_mime_type(&req)?,
- other: BTreeMap::new(), // TODO
- };
+ let headers = get_headers(req)?;
let object_version = ObjectVersion {
uuid: version_uuid,
@@ -444,6 +438,29 @@ fn get_mime_type(req: &Request<Body>) -> Result<String, Error> {
.to_string())
}
+fn get_headers(req: &Request<Body>) -> Result<ObjectVersionHeaders, Error> {
+ let content_type = get_mime_type(req)?;
+ let other_headers = vec![
+ hyper::header::CACHE_CONTROL,
+ hyper::header::CONTENT_DISPOSITION,
+ hyper::header::CONTENT_ENCODING,
+ hyper::header::CONTENT_LANGUAGE,
+ hyper::header::EXPIRES,
+ ];
+ let mut other = BTreeMap::new();
+ for h in other_headers.iter() {
+ if let Some(v) = req.headers().get(h) {
+ if let Ok(v_str) = v.to_str() {
+ other.insert(h.to_string(), v_str.to_string());
+ }
+ }
+ }
+ Ok(ObjectVersionHeaders {
+ content_type,
+ other: BTreeMap::new(),
+ })
+}
+
fn uuid_from_str(id: &str) -> Result<UUID, ()> {
let id_bin = hex::decode(id).map_err(|_| ())?;
if id_bin.len() != 32 {