1// Alchemy modifications are licensed under Apache-2.0.
2// This file includes third-party code; see /THIRD_PARTY_LICENSES.md.
3export class OkResponse extends Response {
4 static readonly status = 200;
5
6 constructor(body: BodyInit | null, init?: ResponseInit) {
7 super(body, {
8 ...init,
9 status: OkResponse.status,
10 });
11 }
12}
13
14export class NotFoundResponse extends Response {
15 static readonly status = 404;
16
17 constructor(...[body, init]: ConstructorParameters<typeof Response>) {
18 super(body, {
19 ...init,
20 status: NotFoundResponse.status,
21 statusText: "Not Found",
22 });
23 }
24}
25
26// A magical response type which is used to signal that a user worker should be invoked if one is present.
27export class NoIntentResponse extends NotFoundResponse {
28 constructor() {
29 super();
30 }
31}
32
33export class MethodNotAllowedResponse extends Response {
34 static readonly status = 405;
35
36 constructor(...[body, init]: ConstructorParameters<typeof Response>) {
37 super(body, {
38 ...init,
39 status: MethodNotAllowedResponse.status,
40 statusText: "Method Not Allowed",
41 });
42 }
43}
44
45export class InternalServerErrorResponse extends Response {
46 static readonly status = 500;
47
48 constructor(_: Error, init?: ResponseInit) {
49 super(null, {
50 ...init,
51 status: InternalServerErrorResponse.status,
52 });
53 }
54}
55
56export class NotModifiedResponse extends Response {
57 static readonly status = 304;
58
59 constructor(...[_body, init]: ConstructorParameters<typeof Response>) {
60 super(null, {
61 ...init,
62 status: NotModifiedResponse.status,
63 statusText: "Not Modified",
64 });
65 }
66}
67
68export class MovedPermanentlyResponse extends Response {
69 static readonly status = 301;
70
71 constructor(location: string, init?: ResponseInit) {
72 super(null, {
73 ...init,
74 status: MovedPermanentlyResponse.status,
75 statusText: "Moved Permanently",
76 headers: {
77 ...init?.headers,
78 Location: location,
79 },
80 });
81 }
82}
83
84export class FoundResponse extends Response {
85 static readonly status = 302;
86
87 constructor(location: string, init?: ResponseInit) {
88 super(null, {
89 ...init,
90 status: FoundResponse.status,
91 statusText: "Found",
92 headers: {
93 ...init?.headers,
94 Location: location,
95 },
96 });
97 }
98}
99
100export class SeeOtherResponse extends Response {
101 static readonly status = 303;
102
103 constructor(location: string, init?: ResponseInit) {
104 super(null, {
105 ...init,
106 status: SeeOtherResponse.status,
107 statusText: "See Other",
108 headers: {
109 ...init?.headers,
110 Location: location,
111 },
112 });
113 }
114}
115
116export class TemporaryRedirectResponse extends Response {
117 static readonly status = 307;
118
119 constructor(location: string, init?: ResponseInit) {
120 super(null, {
121 ...init,
122 status: TemporaryRedirectResponse.status,
123 statusText: "Temporary Redirect",
124 headers: {
125 ...init?.headers,
126 Location: location,
127 },
128 });
129 }
130}
131
132export class PermanentRedirectResponse extends Response {
133 static readonly status = 308;
134
135 constructor(location: string, init?: ResponseInit) {
136 super(null, {
137 ...init,
138 status: PermanentRedirectResponse.status,
139 statusText: "Permanent Redirect",
140 headers: {
141 ...init?.headers,
142 Location: location,
143 },
144 });
145 }
146}