diff --git a/navigation-timing/content-encoding.https.html b/navigation-timing/content-encoding.https.html new file mode 100644 index 00000000000000..5450b5913bd561 --- /dev/null +++ b/navigation-timing/content-encoding.https.html @@ -0,0 +1,36 @@ + + + +
+ + ++ This test validates that when a html is compressed with gzip, navigation timing reports contentEncoding as gzip
+ + + diff --git a/resource-timing/content-encoding.https.html b/resource-timing/content-encoding.https.html new file mode 100644 index 00000000000000..58ea76ed22b2c1 --- /dev/null +++ b/resource-timing/content-encoding.https.html @@ -0,0 +1,107 @@ + + + + + ++ This test validates contentEncoding in resource timing.
+ + + diff --git a/resource-timing/resources/compressed-data.py b/resource-timing/resources/compressed-data.py new file mode 100644 index 00000000000000..8445f762d50c7a --- /dev/null +++ b/resource-timing/resources/compressed-data.py @@ -0,0 +1,33 @@ +def main(request, response): + response.headers.set(b"Content-Type", b"text/plain") + + # `dcb_data` and `dcz_data` are generated using the following commands: + # + # $ echo "This is a test dictionary." > /tmp/dict + # $ echo -n "This is compressed test data using a test dictionary" \ + # > /tmp/data + # + # $ echo -en '\xffDCB' > /tmp/out.dcb + # $ openssl dgst -sha256 -binary /tmp/dict >> /tmp/out.dcb + # $ brotli --stdout -D /tmp/dict /tmp/data >> /tmp/out.dcb + # $ xxd -p /tmp/out.dcb | tr -d '\n' | sed 's/\(..\)/\\x\1/g' + dcb_data = b"\xff\x44\x43\x42\x53\x96\x9b\xcf\x5e\x96\x0e\x0e\xdb\xf0\xa4\xbd\xde\x6b\x0b\x3e\x93\x81\xe1\x56\xde\x7f\x5b\x91\xce\x83\x91\x62\x42\x70\xf4\x16\xa1\x98\x01\x80\x62\xa4\x4c\x1d\xdf\x12\x84\x8c\xae\xc2\xca\x60\x22\x07\x6e\x81\x05\x14\xc9\xb7\xc3\x44\x8e\xbc\x16\xe0\x15\x0e\xec\xc1\xee\x34\x33\x3e\x0d" + # $ echo -en '\x5e\x2a\x4d\x18\x20\x00\x00\x00' > /tmp/out.dcz + # $ openssl dgst -sha256 -binary /tmp/dict >> /tmp/out.dcz + # $ zstd -D /tmp/dict -f -o /tmp/tmp.zstd /tmp/data + # $ cat /tmp/tmp.zstd >> /tmp/out.dcz + # $ xxd -p /tmp/out.dcz | tr -d '\n' | sed 's/\(..\)/\\x\1/g' + dcz_data = b"\x5e\x2a\x4d\x18\x20\x00\x00\x00\x53\x96\x9b\xcf\x5e\x96\x0e\x0e\xdb\xf0\xa4\xbd\xde\x6b\x0b\x3e\x93\x81\xe1\x56\xde\x7f\x5b\x91\xce\x83\x91\x62\x42\x70\xf4\x16\x28\xb5\x2f\xfd\x24\x34\xf5\x00\x00\x98\x63\x6f\x6d\x70\x72\x65\x73\x73\x65\x64\x61\x74\x61\x20\x75\x73\x69\x6e\x67\x03\x00\x59\xf9\x73\x54\x46\x27\x26\x10\x9e\x99\xf2\xbc" + + if b'content_encoding' in request.GET: + content_encoding = request.GET.first(b"content_encoding") + response.headers.set(b"Content-Encoding", content_encoding) + if content_encoding == b"dcb": + # Send the pre compressed file + response.content = dcb_data + if content_encoding == b"dcz": + # Send the pre compressed file + response.content = dcz_data + + if b'allow_origin' in request.GET: + response.headers.set(b'access-control-allow-origin', request.GET.first(b'allow_origin')) diff --git a/resource-timing/resources/compressed-js.py b/resource-timing/resources/compressed-js.py new file mode 100644 index 00000000000000..20207577b97520 --- /dev/null +++ b/resource-timing/resources/compressed-js.py @@ -0,0 +1,29 @@ +import os.path +import zlib +import gzip + +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") + + if b'allow_origin' in request.GET: + response.headers.set( + b'access-control-allow-origin', + request.GET.first(b'allow_origin')) + + if b'content_encoding' in request.GET: + content_encoding = request.GET.first(b"content_encoding") + response.headers.set(b"Content-Encoding", content_encoding) + if content_encoding == b"deflate": + response.content = zlib.compress(read(u"./dummy.js")) + if content_encoding == b"gzip": + response.content = gzip.compress(read(u"./dummy.js")) + if content_encoding == b"identity": + # Uncompressed + response.content = read(u"./dummy.js") + if content_encoding == b"unrecognizedname": + # Just return something + response.content = gzip.compress(read(u"./dummy.js")) diff --git a/resource-timing/resources/dummy.js b/resource-timing/resources/dummy.js new file mode 100644 index 00000000000000..cb7fc3481600bd --- /dev/null +++ b/resource-timing/resources/dummy.js @@ -0,0 +1 @@ +// A dummy js file to be compressed and transferred. diff --git a/resource-timing/resources/foo.text.br b/resource-timing/resources/foo.text.br new file mode 100644 index 00000000000000..30cb2f7095e15a Binary files /dev/null and b/resource-timing/resources/foo.text.br differ diff --git a/resource-timing/resources/foo.text.br.headers b/resource-timing/resources/foo.text.br.headers new file mode 100644 index 00000000000000..8c03b823e09e91 --- /dev/null +++ b/resource-timing/resources/foo.text.br.headers @@ -0,0 +1,2 @@ +Content-type: text/plain +Content-Encoding: br diff --git a/resource-timing/resources/foo.text.gz b/resource-timing/resources/foo.text.gz new file mode 100644 index 00000000000000..05a5cce07b5143 Binary files /dev/null and b/resource-timing/resources/foo.text.gz differ diff --git a/resource-timing/resources/foo.text.gz.headers b/resource-timing/resources/foo.text.gz.headers new file mode 100644 index 00000000000000..7def3ddc148d1c --- /dev/null +++ b/resource-timing/resources/foo.text.gz.headers @@ -0,0 +1,2 @@ +Content-type: text/plain +Content-Encoding: gzip diff --git a/resource-timing/resources/foo.text.zst b/resource-timing/resources/foo.text.zst new file mode 100644 index 00000000000000..a73bbdd22458db Binary files /dev/null and b/resource-timing/resources/foo.text.zst differ diff --git a/resource-timing/resources/foo.text.zst.headers b/resource-timing/resources/foo.text.zst.headers new file mode 100644 index 00000000000000..c5974e126a34d8 --- /dev/null +++ b/resource-timing/resources/foo.text.zst.headers @@ -0,0 +1,2 @@ +Content-type: text/plain +Content-Encoding: zstd diff --git a/resource-timing/resources/gzip_xml.py b/resource-timing/resources/gzip_xml.py index 7debc9ce3f6cb0..b5a0f72d3d4569 100644 --- a/resource-timing/resources/gzip_xml.py +++ b/resource-timing/resources/gzip_xml.py @@ -20,4 +20,7 @@ def main(request, response): (b"Content-Encoding", b"gzip"), (b"Content-Length", len(output))] + if b'allow_origin' in request.GET: + headers.append((b'access-control-allow-origin', request.GET.first(b'allow_origin'))) + return headers, output