From 248691d45298b19d2ed828969227b55b47c7d4ba Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Fri, 18 Nov 2022 06:58:13 -0500 Subject: [PATCH] wpt: add gzip-body.any.js (#1778) * wpt: add gzip-body.any.js * fix: try fixing windows ci failure --- test/wpt/server/server.mjs | 21 +++++++++++++++++- .../fetch/content-encoding/gzip-body.any.js | 16 +++++++++++++ .../resources/foo.octetstream.gz | Bin 0 -> 64 bytes .../resources/foo.octetstream.gz.headers | 2 ++ .../content-encoding/resources/foo.text.gz | Bin 0 -> 57 bytes .../resources/foo.text.gz.headers | 2 ++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/wpt/tests/fetch/content-encoding/gzip-body.any.js create mode 100644 test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz create mode 100644 test/wpt/tests/fetch/content-encoding/resources/foo.octetstream.gz.headers create mode 100644 test/wpt/tests/fetch/content-encoding/resources/foo.text.gz create mode 100644 test/wpt/tests/fetch/content-encoding/resources/foo.text.gz.headers 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 0000000000000000000000000000000000000000..f3df4cb89b5d0b78bc76d0ce03ab0c205c5211fa GIT binary patch literal 64 zcmb2|=HO^#DM@BvPRq~N%TF#zEh#Q3N=?jVczb9gCj$cm(}Miy-}SHi91L?qLSf)O NUv!;XDT^ip0|3Ob6}$id literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..05a5cce07b514365d9c468f4a1763b8173cfecfc GIT binary patch literal 57 zcmb2|=HRGgDM@BvPRq~ND@m;=VR(CJBPRm`1Ji>1=->6P`y32&LqcKTK3{a5S}BVr G0|NjdXcEo< literal 0 HcmV?d00001 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