Skip to content

Commit 3680470

Browse files
author
Marcin Nowak-Liebiediew
committed
use hashmap instead of vec for http headers
1 parent 57006b5 commit 3680470

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/canisters/frontend/ic-certified-assets/src/state_machine.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,19 +709,19 @@ fn build_ok(
709709
callback: Func,
710710
etags: Vec<Hash>,
711711
) -> HttpResponse {
712-
let mut headers = vec![("Content-Type".to_string(), asset.content_type.to_string())];
712+
let mut headers = HashMap::from([("Content-Type".to_string(), asset.content_type.to_string())]);
713713
if enc_name != "identity" {
714-
headers.push(("Content-Encoding".to_string(), enc_name.to_string()));
714+
headers.insert("Content-Encoding".to_string(), enc_name.to_string());
715715
}
716716
if let Some(head) = certificate_header {
717-
headers.push(head);
717+
headers.insert(head.0, head.1);
718718
}
719719
if let Some(max_age) = asset.max_age {
720-
headers.push(("Cache-Control".to_string(), format!("max-age={}", max_age)));
720+
headers.insert("Cache-Control".to_string(), format!("max-age={}", max_age));
721721
}
722722
if let Some(arg_headers) = asset.headers.as_ref() {
723723
for (k, v) in arg_headers {
724-
headers.push((k.to_owned(), v.to_owned()));
724+
headers.insert(k.to_owned(), v.to_owned());
725725
}
726726
}
727727

@@ -731,16 +731,16 @@ fn build_ok(
731731
let (status_code, body) = if etags.contains(&enc.sha256) {
732732
(304, RcBytes::default())
733733
} else {
734-
headers.push((
734+
headers.insert(
735735
"ETag".to_string(),
736736
format!("\"{}\"", hex::encode(enc.sha256)),
737-
));
737+
);
738738
(200, enc.content_chunks[chunk_index].clone())
739739
};
740740

741741
HttpResponse {
742742
status_code,
743-
headers,
743+
headers: headers.into_iter().collect::<_>(),
744744
body,
745745
streaming_strategy,
746746
}
-39.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)