Skip to content

Commit

Permalink
Use the new "dcb" and "dcz" content encodings of Compressed Dictionary
Browse files Browse the repository at this point in the history
The spec of Compression Dictionary Transport has been changed to use
new `dcb` and `dcz` content encodings.
httpwg/http-extensions#2784

To follow the spec change, this CL changes the Chromium implementation
and tests as follows:

- Use "dcb" content encoding name instead of "br-d".
- Use "dcz" content encoding name instead of "zstd-d".
- Remove the "Content-Dictionary" response header.
- Check the magic number and the sha256 hash in the head of the
  Dictionary-Compressed streams using
  SharedDictionaryHeaderCheckerSourceStream.
- Re-generate test files using the new content encodings.

Bug: 1413922
Change-Id: I4f2f40c1f0c3666b4f0b54e34ad966ffccadd96b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5552563
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Patrick Meenan <pmeenan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1304826}
  • Loading branch information
horo-t authored and chromium-wpt-export-bot committed May 23, 2024
1 parent bb1a8e8 commit 0af64c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// Check if the data compressed using Brotli with the dictionary can be
// decompressed.
const data_url = `${kCompressedDataPath}?content_encoding=br-d`;
const data_url = `${kCompressedDataPath}?content_encoding=dcb`;
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Decompresion using Brotli with the dictionary works as expected');

Expand All @@ -34,7 +34,7 @@

// Check if the data compressed using Zstandard with the dictionary can be
// decompressed.
const data_url = `${kCompressedDataPath}?content_encoding=zstd-d`;
const data_url = `${kCompressedDataPath}?content_encoding=dcz`;
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Decompresion using Zstandard with the dictionary works as expected');

Expand All @@ -50,7 +50,7 @@
// Check if the data compressed using Brotli with the dictionary can be
// decompressed.
const data_url =
getRemoteHostUrl(`${kCompressedDataPath}?content_encoding=br-d`);
getRemoteHostUrl(`${kCompressedDataPath}?content_encoding=dcb`);
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Decompresion of a cross origin resource works as expected');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
kDefaultDictionaryHashBase64);
// Check if the data compressed using Brotli with the dictionary can be
// decompressed.
const data_url = `${kCompressedDataPath}?content_encoding=br-d`;
const data_url = `${kCompressedDataPath}?content_encoding=dcb`;
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Fetch same origin dictionary using link element');

Expand All @@ -64,7 +64,7 @@
// Check if the data compressed using Brotli with the dictionary can be
// decompressed.
const data_url =
getRemoteHostUrl(`${kCompressedDataPath}?content_encoding=br-d`);
getRemoteHostUrl(`${kCompressedDataPath}?content_encoding=dcb`);
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Fetch cross origin dictionary using link element');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
kDefaultDictionaryHashBase64);
// Check if the data compressed using Brotli with the dictionary can be
// decompressed.
const data_url = `${kCompressedDataPath}?content_encoding=br-d`;
const data_url = `${kCompressedDataPath}?content_encoding=dcb`;
assert_equals(await (await fetch(data_url)).text(), kExpectedCompressedData);
}, 'Fetch same origin dictionary using link header');

Expand Down
31 changes: 17 additions & 14 deletions fetch/compression-dictionary/resources/compressed-data.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
def main(request, response):
response.headers.set(b"Access-Control-Allow-Origin", b"*")
response.headers.set(b"Content-Type", b"text/plain")
response.headers.set(
b"Content-Dictionary",
b":U5abz16WDg7b8KS93msLPpOB4Vbef1uRzoORYkJw9BY=:")

# `br_d_data` and `zstd_d_data` are generated using the following commands:
# `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
# $ brotli -o /tmp/out.brd -D /tmp/dict /tmp/data
# $ xxd -p /tmp/out.brd | tr -d '\n' | sed 's/\(..\)/\\x\1/g'
br_d_data = b"\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"
# $ zstd -o /tmp/out.zstdd -D /tmp/dict /tmp/data
# $ xxd -p /tmp/out.zstdd | tr -d '\n' | sed 's/\(..\)/\\x\1/g'
zstd_d_data = b"\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"
#
# $ 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"br-d":
if content_encoding == b"dcb":
# Send the pre compressed file
response.content = br_d_data
if content_encoding == b"zstd-d":
response.content = dcb_data
if content_encoding == b"dcz":
# Send the pre compressed file
response.content = zstd_d_data
response.content = dcz_data

0 comments on commit 0af64c1

Please sign in to comment.