Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend-canister): allow overwriting default HTTP headers #2689

Merged
merged 32 commits into from Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3680470
use hashmap instead of vec for http headers
Oct 14, 2022
2ce8a22
changelog
Oct 14, 2022
518f7ad
update asset canister wasm
Oct 14, 2022
46ce531
trying to update asset canister wasm again (to pass ci tests)
Oct 14, 2022
798d98b
fix: apply Eric's suggestions
Oct 17, 2022
ad27584
Merge branch 'master' into mnl/fix--allow-overwritting-default-headers
Oct 17, 2022
936e387
update canister wasm
Oct 17, 2022
a17be27
try using apple gzip instead of brew gzip
Oct 17, 2022
1b570d3
Update build-frontend-canister.yml
Oct 17, 2022
97a95fb
add `--locked` to cargo build in `scripts/update-froentend-canister.sh`
Oct 17, 2022
b529231
use `macos-latest` instead of `ubuntu` in frontend canister building GHA
Oct 17, 2022
1ab6340
comment some stuff from gha workflow
Oct 17, 2022
a1006ab
try to use gnu readlink
Oct 17, 2022
915a090
back to ubuntu, trying to disable ic-wasm
Oct 17, 2022
884e49b
^ forgot to upload wasm
Oct 17, 2022
26e853b
disable everything besides `cargo build`
Oct 17, 2022
e99c868
use ubuntu 20.04 (instead of latest (22.04))
Oct 17, 2022
a368d69
use macos-latest, only cargo build --release (no gzip nor ic-wasm)
Oct 17, 2022
9c8a07f
recreated cargo.lock file
Oct 17, 2022
54c24d0
trying `rust-toolchain:channel=stable`
Oct 17, 2022
6783976
use macos-12 instead of latest (11.7)
Oct 17, 2022
f778015
revert commits aimed at trying to pass failing CI
Oct 18, 2022
5607c48
Merge branch 'master' into mnl/fix--allow-overwritting-default-headers
Oct 18, 2022
60930b6
reupload wasm (downloaded from CI's artifacts)
Oct 18, 2022
2c5daac
reupload wasm (downloaded from CI's artifacts)
Oct 18, 2022
81e98c7
reupload wasm (downloaded from CI's artifacts)
Oct 18, 2022
2daebfa
Merge branch 'master' into mnl/fix--allow-overwritting-default-headers
Oct 18, 2022
64e54de
changelog - notice about updated frontend wasm
Oct 19, 2022
3e9be0f
Merge branch 'master' into mnl/fix--allow-overwritting-default-headers
Oct 19, 2022
d0598e9
add e2e test
Oct 19, 2022
27efc0e
trim
Oct 19, 2022
5fa818d
fix testing `etag` header
Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,22 @@

## DFX

### fix(frontend-canister): Allow overwirting default HTTP Headers for assets in frontend canister
smallstepman marked this conversation as resolved.
Show resolved Hide resolved

Allows to overwrite `Content-Type`, `Content-Encoding`, and `Cache-Control` HTTP headers with custom values via `.ic-assets.json5` config file. Notice this requires using correct capitalization, example `.ic-assets.json5` file:
```json5
[
{
"match": "web-gz.data.gz",
"headers": {
"Content-Type": "application/octet-stream",
"Content-Encoding": "gzip"
}
},
]
```
smallstepman marked this conversation as resolved.
Show resolved Hide resolved


smallstepman marked this conversation as resolved.
Show resolved Hide resolved
### fix: Save SNS canister IDs

SNS canister IDs were not being parsed reliably. Now the candid file is being specified explicitly, which resolves the issue in at least some cases.
Expand Down
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.