Skip to content

Truly independent web browser

1.8 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<script>
    promiseTest(async () => {
        for (const method of ["GET", "POST"]) {
            const cookieName = `malformedbodycookie-${method.toLowerCase()}`;
            const responseURL = await httpTestServer().createEcho(method, `/malformed-content-encoding-${method}`, {
                status: 200,
                headers: {
                    "Content-Type": "text/plain",
                    "Content-Encoding": "gzip",
                    "Set-Cookie": `${cookieName}=stored; Path=/`,
                    "Cache-Control": "no-store",
                },
                body: "not actually gzip",
            });
            try {
                const response = await fetch(responseURL, { method, credentials: "include" });
                println(`${method} status: ${response.status}`);
                try {
                    await response.text();
                    println(`${method} body unexpectedly resolved`);
                } catch (error) {
                    println(`${method} body: ${error.name}`);
                }
                const echoURL = await httpTestServer().createEcho("GET", `/malformed-content-encoding-cookie-${method}`, {
                    status: 200,
                    headers: { "Content-Type": "application/json" },
                    body: "$HEADERS",
                    reflect_headers_in_body: true,
                });
                const headers = await (await fetch(echoURL, { credentials: "include" })).json();
                const cookie = headers["Cookie"]?.some(value => value.includes(`${cookieName}=stored`));
                println(`${method} cookie stored: ${!!cookie}`);
            } catch (error) {
                println(`${method} fetch: ${error.name}`);
            }
        }
    });
</script>