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 all 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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,22 @@

## DFX

### fix(frontend-canister): Allow overwriting default HTTP Headers for assets in frontend canister

Allows to overwrite `Content-Type`, `Content-Encoding`, and `Cache-Control` HTTP headers with custom values via `.ic-assets.json5` config file. Example `.ic-assets.json5` file:
```json5
[
{
"match": "web-gz.data.gz",
"headers": {
"Content-Type": "application/octet-stream",
"Content-Encoding": "gzip"
}
}
]
```
This change will trigger the update process for frontend canister (new module hash: `2ff0513123f11c57716d889ca487083fac7d94a4c9434d5879f8d0342ad9d759`).

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 @@ -501,6 +517,10 @@ Updated ic-ref to 0.0.1-1fba03ee
- Module hash: b944b1e5533064d12e951621d5045d5291bcfd8cf9d60c28fef02c8fdb68e783
- https://github.com/dfinity/cycles-wallet/commit/fa86dd3a65b2509ca1e0c2bb9d7d4c5be95de378

### Frontend canister:
- Module hash: 2ff0513123f11c57716d889ca487083fac7d94a4c9434d5879f8d0342ad9d759
- https://github.com/dfinity/sdk/pull/2689

# 0.11.2

## DFX
Expand Down
33 changes: 33 additions & 0 deletions e2e/tests-dfx/assetscanister.bash
Expand Up @@ -506,3 +506,36 @@ CHERRIES" "$stdout"
assert_match "HTTP/1.1 404 Not Found"

}

@test "asset configuration via .ic-assets.json5 - overwriting default headers" {
install_asset assetscanister

dfx_start

touch src/e2e_project_frontend/assets/thing.json

echo '[
{
"match": "thing.json",
"cache": { "max_age": 2000 },
"headers": {
"Content-Encoding": "my-encoding",
"Content-Type": "x-type",
"Cache-Control": "custom",
"etag": "my-etag"
}
}
]' > src/e2e_project_frontend/assets/.ic-assets.json5

dfx deploy

ID=$(dfx canister id e2e_project_frontend)
PORT=$(get_webserver_port)

assert_command curl --head "http://localhost:$PORT/thing.json?canisterId=$ID"
assert_match "cache-control: custom"
assert_match "content-encoding: my-encoding"
assert_match "content-type: x-type"
assert_not_match "etag: my-etag"
assert_match "etag: \"[a-z0-9]{64}\""
}
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().to_lowercase(), 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((
"ETag".to_string(),
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 100755 → 100644
Binary file not shown.