diff --git a/test/wpt/server/server.mjs b/test/wpt/server/server.mjs index 705fe581af2..c62f9658053 100644 --- a/test/wpt/server/server.mjs +++ b/test/wpt/server/server.mjs @@ -3,7 +3,7 @@ import { createServer } from 'node:http' import { join } from 'node:path' import process from 'node:process' import { fileURLToPath } from 'node:url' -import { createReadStream, readFileSync } from 'node:fs' +import { createReadStream, readFileSync, existsSync } from 'node:fs' import { setTimeout as sleep } from 'node:timers/promises' import { route as networkPartitionRoute } from './routes/network-partition-key.mjs' import { route as redirectRoute } from './routes/redirect.mjs' @@ -32,6 +32,8 @@ const server = createServer(async (req, res) => { const fullUrl = new URL(req.url, `http://localhost:${server.address().port}`) switch (fullUrl.pathname) { + case '/fetch/content-encoding/resources/foo.octetstream.gz': + case '/fetch/content-encoding/resources/foo.text.gz': case '/fetch/api/resources/cors-top.txt': case '/fetch/api/resources/top.txt': case '/mimesniff/mime-types/resources/generated-mime-types.json': @@ -47,6 +49,23 @@ const server = createServer(async (req, res) => { case '/fetch/data-urls/resources/data-urls.json': case '/fetch/api/resources/empty.txt': case '/fetch/api/resources/data.json': { + // If this specific resources requires custom headers + const customHeadersPath = join(tests, fullUrl.pathname + '.headers') + if (existsSync(customHeadersPath)) { + const headers = readFileSync(customHeadersPath, 'utf-8') + .trim() + .split(/\r?\n/g) + .map((h) => h.split(': ')) + + for (const [key, value] of headers) { + if (!key || !value) { + console.warn(`Skipping ${key}:${value} header pair`) + continue + } + res.setHeader(key, value) + } + } + // https://github.com/web-platform-tests/wpt/blob/6ae3f702a332e8399fab778c831db6b7dca3f1c6/fetch/api/resources/data.json return createReadStream(join(tests, fullUrl.pathname)) .on('end', () => res.end()) diff --git a/test/wpt/tests/fetch/content-encoding/gzip-body.any.js b/test/wpt/tests/fetch/content-encoding/gzip-body.any.js new file mode 100644 index 00000000000..37758b7d917 --- /dev/null +++ b/test/wpt/tests/fetch/content-encoding/gzip-body.any.js @@ -0,0 +1,16 @@ +// META: global=window,worker + +const expectedDecompressedSize = 10500; +[ + "text", + "octetstream" +].forEach(contentType => { + promise_test(async t => { + let response = await fetch(`resources/foo.${contentType}.gz`); + assert_true(response.ok); + let arrayBuffer = await response.arrayBuffer() + let u8 = new Uint8Array(arrayBuffer); + assert_equals(u8.length, expectedDecompressedSize); + }, `fetched gzip data with content type ${contentType} should be decompressed.`); +}); + diff --git a/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz b/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz new file mode 100644 index 00000000000..f3df4cb89b5 Binary files /dev/null and b/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz differ diff --git a/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz.headers b/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz.headers new file mode 100644 index 00000000000..27d4f401f1b --- /dev/null +++ b/test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz.headers @@ -0,0 +1,2 @@ +Content-type: application/octet-stream +Content-Encoding: gzip diff --git a/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz b/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz new file mode 100644 index 00000000000..05a5cce07b5 Binary files /dev/null and b/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz differ diff --git a/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz.headers b/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz.headers new file mode 100644 index 00000000000..7def3ddc148 --- /dev/null +++ b/test/wpt/tests/fetch/content-encoding/resources/foo.text.gz.headers @@ -0,0 +1,2 @@ +Content-type: text/plain +Content-Encoding: gzip