This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Add matching allowed-alt-sxg for preloads.#57
Merged
twifkak merged 4 commits intogoogle:mainfrom Sep 14, 2021
Merged
Conversation
For each same-origin `Link: rel=preload` directive, fetch the subresource, sign it, compute its header-integrity, and construct a corresponding `Link: rel=allowed-alt-sxg`. This allows subresource substitution [1], for prefetching subresources via the Google SXG Cache [2]. Header-integrity values are cached, since fetching and signing each subresource is expensive. If there is an error in fetching or signing, then the error status is also cached; this reduces the traffic to the origin caused by preloading a resource that can't be signed. To facilitate integration with the environment: - Added a subresource_fetcher parameter which is an implementation of Fetcher, but may be different from the OCSP fetcher if desired. - Created an HttpCache trait, and provided an implementation which wraps the Service Workers Cache API [3], as provided by Cloudflare Workers [4]. - Added a HeaderIntegrityFetcher interface, with a default implementation that uses the above two. Useful in test to stub out the whole thing. Extracted the computation of CBOR headers and MICE payload from SxgWorker into utils::signed_headers_and_payload, for reuse in HeaderIntegrityFetcher. Moved the requirement for status code 200 from index.ts to signed_headers_and_payload. This also implements the requirement for fastly_compute. In the fetchers for both cloudflare_worker and fastly_compute, add an 8MB response body limit, after which an error is returned. In cloudflare_worker, only attach a request body if it is non-empty; this addresses an error message that bodies are disallowed on GET requests. TODO: Issue these subresource fetches concurrently, to speed up processing on cache miss. [1] https://github.com/WICG/webpackage/blob/main/explainers/signed-exchange-subresource-substitution.md [2] https://github.com/google/webpackager/blob/main/docs/cache_requirements.md [3] https://developer.mozilla.org/en-US/docs/Web/API/Cache [4] https://developers.cloudflare.com/workers/runtime-apis/cache
4ef2409 to
4006773
Compare
banaag
reviewed
Sep 14, 2021
banaag
reviewed
Sep 14, 2021
antiphoton
approved these changes
Sep 14, 2021
banaag
approved these changes
Sep 14, 2021
- Change the error from TS to be a 404 (not 406) so Rust knows to fetch from origin. - Add a comment when an error response is found in the cache. - Change name in wasmFunctions to match TS style. - Update unsafe comment to say there's no data race.
Contributor
Author
|
Addresses #13. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For each same-origin
Link: rel=preload directive, fetch the subresource, signit, compute its header-integrity, and construct a corresponding
Link: rel=allowed-alt-sxg. This allows subresource substitution [1], as required bythe Google SXG Cache for any preloads [2].
Header-integrity values are cached, since fetching and signing each subresource
is expensive. If there is an error in fetching or signing, then the error
status is also cached; this reduces the traffic to the origin caused by
preloading a resource that can't be signed.
To facilitate integration with the environment:
but may be different from the OCSP fetcher if desired.
service workers Cache API [3], as provided by Cloudflare Workers [4].
uses the above two. Useful in test to stub out the whole thing.
Extracted the computation of CBOR headers and MICE payload from SxgWorker into
utils::signed_headers_and_payload, for reuse in HeaderIntegrityFetcher.
Moved the requirement for status code 200 from index.ts to
signed_headers_and_payload. This also implements the requirement for fastly_compute.
In the fetchers for both cloudflare_worker and fastly_compute, add an 8MB
response body limit, after which an error is returned. In cloudflare_worker,
only attach a request body if it is non-empty; this addresses an error message
that bodies are disallowed on GET requests.
TODO: Issue these subresource fetches concurrently, to speed up processing on
cache miss.
[1] https://github.com/WICG/webpackage/blob/main/explainers/signed-exchange-subresource-substitution.md
[2] https://github.com/google/webpackager/blob/main/docs/cache_requirements.md
[3] https://developer.mozilla.org/en-US/docs/Web/API/Cache
[4] https://developers.cloudflare.com/workers/runtime-apis/cache
/cc @oliy