Skip to content

Commit

Permalink
use hashmap instead of vec for http headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Nowak-Liebiediew committed Oct 14, 2022
1 parent 57006b5 commit 3680470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/canisters/frontend/ic-certified-assets/src/state_machine.rs
Expand Up @@ -709,19 +709,19 @@ fn build_ok(
callback: Func,
etags: Vec<Hash>,
) -> HttpResponse {
let mut headers = vec![("Content-Type".to_string(), asset.content_type.to_string())];
let mut headers = HashMap::from([("Content-Type".to_string(), asset.content_type.to_string())]);
if enc_name != "identity" {
headers.push(("Content-Encoding".to_string(), enc_name.to_string()));
headers.insert("Content-Encoding".to_string(), enc_name.to_string());
}
if let Some(head) = certificate_header {
headers.push(head);
headers.insert(head.0, head.1);
}
if let Some(max_age) = asset.max_age {
headers.push(("Cache-Control".to_string(), format!("max-age={}", max_age)));
headers.insert("Cache-Control".to_string(), format!("max-age={}", max_age));
}
if let Some(arg_headers) = asset.headers.as_ref() {
for (k, v) in arg_headers {
headers.push((k.to_owned(), v.to_owned()));
headers.insert(k.to_owned(), v.to_owned());
}
}

Expand All @@ -731,16 +731,16 @@ fn build_ok(
let (status_code, body) = if etags.contains(&enc.sha256) {
(304, RcBytes::default())
} else {
headers.push((
headers.insert(
"ETag".to_string(),
format!("\"{}\"", hex::encode(enc.sha256)),
));
);
(200, enc.content_chunks[chunk_index].clone())
};

HttpResponse {
status_code,
headers,
headers: headers.into_iter().collect::<_>(),
body,
streaming_strategy,
}
Expand Down
Binary file modified src/distributed/assetstorage.wasm.gz
Binary file not shown.

0 comments on commit 3680470

Please sign in to comment.