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

Add Response.prototype.type property #3590

Merged
merged 2 commits into from
Feb 24, 2025
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: 7 additions & 0 deletions src/workerd/api/http-standard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ export const test = {
strictEqual(await resp.text(), 'ok');
},
};

export const typeTest = {
test() {
const resp = new Response('ok');
strictEqual(resp.type, 'default');
},
};
1 change: 1 addition & 0 deletions src/workerd/api/http-test-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const cacheMode = {
url: 'http://placeholder/not-found',
webSocket: null,
cf: undefined,
type: 'default',
body: ReadableStream {
locked: false,
[state]: 'readable',
Expand Down
2 changes: 2 additions & 0 deletions src/workerd/api/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const inspect = {
url: 'http://placeholder/not-found',
webSocket: null,
cf: undefined,
type: 'default',
body: ReadableStream {
locked: false,
[state]: 'readable',
Expand Down Expand Up @@ -329,6 +330,7 @@ export const cacheMode = {
url: 'http://placeholder/not-found',
webSocket: null,
cf: undefined,
type: 'default',
body: ReadableStream {
locked: false,
[state]: 'readable',
Expand Down
20 changes: 10 additions & 10 deletions src/workerd/api/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,10 @@ class Response final: public Body {

// This relates to CORS, which doesn't apply on the edge -- see Request::Initializer::mode.
// In discussing with other runtime implementations that do not implement CORS, it was
// determined that just have this property as undefined is the best option.
// jsg::JsValue getType(jsg::Lock& js) { return js.v8Undefined(); }
// TODO(conform): Won't implement?
// determined that only the `'default'` and `'error'` properties should be implemented.
// We currently due not implement Response.error() so "default" is the only value we
// currently support.
kj::StringPtr getType() { return "default"_kj; }

JSG_RESOURCE_TYPE(Response, CompatibilityFlags::Reader flags) {
JSG_INHERIT(Body);
Expand All @@ -1161,9 +1162,7 @@ class Response final: public Body {

JSG_READONLY_PROTOTYPE_PROPERTY(cf, getCf);

// TODO(conform): This is a standard properties that we do not implement (see description
// above).
// JSG_READONLY_PROTOTYPE_PROPERTY(type, getType);
JSG_READONLY_PROTOTYPE_PROPERTY(type, getType);
} else {
JSG_READONLY_INSTANCE_PROPERTY(status, getStatus);
JSG_READONLY_INSTANCE_PROPERTY(statusText, getStatusText);
Expand All @@ -1177,12 +1176,13 @@ class Response final: public Body {

JSG_READONLY_INSTANCE_PROPERTY(cf, getCf);

// TODO(conform): This is a standard properties that we do not implement (see description
// above).
// JSG_READONLY_INSTANCE_PROPERTY(type, getType);
JSG_READONLY_INSTANCE_PROPERTY(type, getType);
}

JSG_TS_OVERRIDE({ constructor(body?: BodyInit | null, init?: ResponseInit); });
JSG_TS_OVERRIDE({
constructor(body?: BodyInit | null, init?: ResponseInit);
type: 'default' | 'error';
});
// Use `BodyInit` and `ResponseInit` type aliases in constructor instead of inlining
}

Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2021-11-03/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,8 @@ interface Response extends Body {
readonly url: string;
readonly webSocket: WebSocket | null;
readonly cf?: any;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2021-11-03/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,8 @@ export interface Response extends Body {
readonly url: string;
readonly webSocket: WebSocket | null;
readonly cf?: any;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-01-31/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-01-31/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-03-21/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-03-21/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-08-04/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-08-04/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-10-31/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-10-31/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-11-30/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2022-11-30/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2023-03-01/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2023-03-01/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2023-07-01/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/2023-07-01/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/experimental/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,8 @@ interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,8 @@ export interface Response extends Body {
url: string;
webSocket: WebSocket | null;
cf: any | undefined;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/oldest/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,8 @@ interface Response extends Body {
readonly url: string;
readonly webSocket: WebSocket | null;
readonly cf?: any;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
interface ResponseInit {
status?: number;
Expand Down
2 changes: 2 additions & 0 deletions types/generated-snapshot/oldest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,8 @@ export interface Response extends Body {
readonly url: string;
readonly webSocket: WebSocket | null;
readonly cf?: any;
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */
type: "default" | "error";
}
export interface ResponseInit {
status?: number;
Expand Down