Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: support for 101 status code #6059

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cli/js/web/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -329,14 +329,15 @@ export async function fetch(
}

responseInit = {
status: fetchResponse.status,
status: 200,
statusText: fetchResponse.statusText,
headers: fetchResponse.headers,
};

responseData.set(responseInit, {
redirected,
rid: fetchResponse.bodyRid,
status: fetchResponse.status,
url,
});

Expand Down
22 changes: 21 additions & 1 deletion cli/tests/unit/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchNullBodyStatus(): Promise<void> {
const nullBodyStatus = [204, 205, 304];
const nullBodyStatus = [101, 204, 205, 304];

for (const status of nullBodyStatus) {
const headers = new Headers([["x-status", String(status)]]);
Expand Down Expand Up @@ -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]`
);
}
}
}
);