Skip to content

Commit

Permalink
Revise filtering for Content-Encoding in ResourceTiming
Browse files Browse the repository at this point in the history
The value from the http header can be of multiple codings, or not
properly formatted.

Per discussion on w3c/resource-timing#381,
multiple codings should be transformed to "multiple"; "identity" is
not allowed in response header; and the coding value should be
formatted if it's not in http header.

Bug: 327941462
Change-Id: I9048423c5ad562d8001562324cb35f72ef8ac5da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6215331
Reviewed-by: Noam Rosenthal <[email protected]>
Reviewed-by: Yoav Weiss (@Shopify) <[email protected]>
Commit-Queue: Guohui Deng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1415037}
  • Loading branch information
Guohui Deng authored and chromium-wpt-export-bot committed Feb 3, 2025
1 parent c725921 commit 1691f56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions resource-timing/content-encoding.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@
run_same_origin_test("/resource-timing/resources/foo.text.zst", "zstd");
run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate");
run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip");
run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=identity", "identity");
// Unrecognized content encoding value should be transformed to "unknown".
run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=unrecognizedname", "unknown");

// "identity" is not allowed in response header and should be transformed to "unknown".
run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=identity", "unknown");
// Mult-encodinging and formatting tests.
run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, deflate,Apple", "multiple");
run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, ", "multiple");
run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gZip ", "gzip");
// Empty value test.
run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=", "");

const run_cross_origin_test = (path) => {
const url = new URL(path, REMOTE_ORIGIN);
Expand Down
15 changes: 15 additions & 0 deletions resource-timing/resources/content-encoding-headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os.path

# Return arbitory content-encoding header value.

def read(file):
path = os.path.join(os.path.dirname(__file__), file)
return open(path, u"rb").read()

def main(request, response):
response.headers.set(b"Content-Type", b"text/javascript")
response.content = read(u"./dummy.js")

if b'content_encoding' in request.GET:
content_encoding = request.GET.first(b"content_encoding")
response.headers.set(b"Content-Encoding", content_encoding)

0 comments on commit 1691f56

Please sign in to comment.