From 25203e9c4ad7e78dfea4aa32d728d1a0e8daa9b7 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Wed, 3 Jun 2020 01:29:23 +0200 Subject: [PATCH] Support 101 status code --- cli/js/web/fetch.ts | 7 ++++--- cli/tests/unit/fetch_test.ts | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index 1f0242a9676ffe..47ed1a7d17a93d 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -12,7 +12,7 @@ import { DomFileImpl } from "./dom_file.ts"; import { getHeaderValueParams } from "./util.ts"; import { ReadableStreamImpl } from "./streams/readable_stream.ts"; -const NULL_BODY_STATUS = [/* 101, */ 204, 205, 304]; +const NULL_BODY_STATUS = [101, 204, 205, 304]; const REDIRECT_STATUS = [301, 302, 303, 307, 308]; const responseData = new WeakMap(); @@ -115,7 +115,7 @@ export class Response extends Body.Body implements domTypes.Response { this.url = url; this.statusText = statusText; - this.status = status; + this.status = extraInit.status || status; this.headers = headers; this.redirected = extraInit.redirected; this.type = type; @@ -329,7 +329,7 @@ export async function fetch( } responseInit = { - status: fetchResponse.status, + status: 200, statusText: fetchResponse.statusText, headers: fetchResponse.headers, }; @@ -337,6 +337,7 @@ export async function fetch( responseData.set(responseInit, { redirected, rid: fetchResponse.bodyRid, + status: fetchResponse.status, url, }); diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index b95ecfb9694897..7c054c9642ca2a 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -767,7 +767,7 @@ unitTest( unitTest( { perms: { net: true } }, async function fetchNullBodyStatus(): Promise { - const nullBodyStatus = [204, 205, 304]; + const nullBodyStatus = [101, 204, 205, 304]; for (const status of nullBodyStatus) { const headers = new Headers([["x-status", String(status)]]); @@ -801,3 +801,23 @@ unitTest( } } ); + +unitTest( + { perms: { net: true } }, + function fetchResponseConstructorInvalidStatus(): void { + const invalidStatus = [101, 600, 199]; + + for (const status of invalidStatus) { + try { + new Response("deno", { status }); + fail("Invalid status"); + } catch (e) { + assert(e instanceof RangeError); + assertEquals( + e.message, + `The status provided (${status}) is outside the range [200, 599]` + ); + } + } + } +);