Files
wehub-resource-sync 70bf21e064
Handle Changesets / Handle Changesets (push) Waiting to run
Semgrep OSS scan / semgrep-oss (push) Waiting to run
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

145 lines
3.0 KiB
TypeScript

export class OkResponse extends Response {
static readonly status = 200;
constructor(body: BodyInit | null, init?: ResponseInit) {
super(body, {
...init,
status: OkResponse.status,
});
}
}
export class NotFoundResponse extends Response {
static readonly status = 404;
constructor(...[body, init]: ConstructorParameters<typeof Response>) {
super(body, {
...init,
status: NotFoundResponse.status,
statusText: "Not Found",
});
}
}
// A magical response type which is used to signal that a user worker should be invoked if one is present.
export class NoIntentResponse extends NotFoundResponse {
constructor() {
super();
}
}
export class MethodNotAllowedResponse extends Response {
static readonly status = 405;
constructor(...[body, init]: ConstructorParameters<typeof Response>) {
super(body, {
...init,
status: MethodNotAllowedResponse.status,
statusText: "Method Not Allowed",
});
}
}
export class InternalServerErrorResponse extends Response {
static readonly status = 500;
constructor(_: Error, init?: ResponseInit) {
super(null, {
...init,
status: InternalServerErrorResponse.status,
});
}
}
export class NotModifiedResponse extends Response {
static readonly status = 304;
constructor(...[_body, init]: ConstructorParameters<typeof Response>) {
super(null, {
...init,
status: NotModifiedResponse.status,
statusText: "Not Modified",
});
}
}
export class MovedPermanentlyResponse extends Response {
static readonly status = 301;
constructor(location: string, init?: ResponseInit) {
super(null, {
...init,
status: MovedPermanentlyResponse.status,
statusText: "Moved Permanently",
headers: {
...init?.headers,
Location: location,
},
});
}
}
export class FoundResponse extends Response {
static readonly status = 302;
constructor(location: string, init?: ResponseInit) {
super(null, {
...init,
status: FoundResponse.status,
statusText: "Found",
headers: {
...init?.headers,
Location: location,
},
});
}
}
export class SeeOtherResponse extends Response {
static readonly status = 303;
constructor(location: string, init?: ResponseInit) {
super(null, {
...init,
status: SeeOtherResponse.status,
statusText: "See Other",
headers: {
...init?.headers,
Location: location,
},
});
}
}
export class TemporaryRedirectResponse extends Response {
static readonly status = 307;
constructor(location: string, init?: ResponseInit) {
super(null, {
...init,
status: TemporaryRedirectResponse.status,
statusText: "Temporary Redirect",
headers: {
...init?.headers,
Location: location,
},
});
}
}
export class PermanentRedirectResponse extends Response {
static readonly status = 308;
constructor(location: string, init?: ResponseInit) {
super(null, {
...init,
status: PermanentRedirectResponse.status,
statusText: "Permanent Redirect",
headers: {
...init?.headers,
Location: location,
},
});
}
}