UNPKG

5.15 kBJavaScriptView Raw
1const mkResponse = (status, statusText) => (body = null, init = {}) => new Response(body, {
2 ...init,
3 status,
4 statusText,
5});
6const mkRedirect = (status, statusText) => (location, init = {}) => new Response(null, {
7 ...init,
8 status,
9 statusText,
10 headers: [
11 ...(init === null || init === void 0 ? void 0 : init.headers) ? Array.isArray(init.headers) ? init.headers : new Headers(init.headers) : [],
12 ['Location', location.toString()],
13 ],
14});
15const mkUnauthorized = (status, statusText) => (realm = '', init = {}) => new Response(null, {
16 ...init,
17 status,
18 statusText,
19 headers: [
20 ...(init === null || init === void 0 ? void 0 : init.headers) ? Array.isArray(init.headers) ? init.headers : new Headers(init.headers) : [],
21 ['WWW-Authenticate', `Basic realm="${realm}", charset="UTF-8"`],
22 ],
23});
24const mkNotModified = (status, statusText) => (ifNoneMatch, ifModifiedSince, init = {}) => new Response(null, {
25 ...init,
26 status,
27 statusText,
28 headers: [
29 ...(init === null || init === void 0 ? void 0 : init.headers) ? Array.isArray(init.headers) ? init.headers : new Headers(init.headers) : [],
30 ['If-None-Match', ifNoneMatch],
31 ['If-Modified-Since', ifModifiedSince.toUTCString()],
32 ],
33});
34export const ok = mkResponse(200, 'OK');
35export const created = mkResponse(201, 'Created');
36export const accepted = mkResponse(202, 'Accepted');
37export const nonAuthoritativeInformation = mkResponse(203, 'Non-Authoritative Information');
38export const noContent = mkResponse(204, 'No Content');
39export const resetContent = mkResponse(205, 'Reset Content');
40export const partialContent = mkResponse(206, 'Partial Content');
41export const multiStatus = mkResponse(207, 'Multi-Status');
42export const alreadyReported = mkResponse(208, 'Already Reported');
43export const imUsed = mkResponse(226, 'IM Used');
44export const multipleChoices = mkRedirect(300, 'Multiple Choices');
45export const movedPermanently = mkRedirect(301, 'Moved Permanently');
46export const found = mkRedirect(302, 'Found');
47export const seeOther = mkRedirect(303, 'See Other');
48export const notModified = mkNotModified(304, 'Not Modified');
49export const temporaryRedirect = mkRedirect(307, 'Temporary Redirect');
50export const permanentRedirect = mkRedirect(308, 'Permanent Redirect');
51export const badRequest = mkResponse(400, 'Bad Request');
52export const unauthorized = mkUnauthorized(401, 'Unauthorized');
53export const paymentRequired = mkResponse(402, 'Payment Required');
54export const forbidden = mkResponse(403, 'Forbidden');
55export const notFound = mkResponse(404, 'Not Found');
56export const methodNotAllowed = mkResponse(405, 'Method Not Allowed');
57export const notAcceptable = mkResponse(406, 'Not Acceptable');
58export const proxyAuthenticationRequired = mkResponse(407, 'Proxy Authentication Required');
59export const requestTimeout = mkResponse(408, 'Request Timeout');
60export const conflict = mkResponse(409, 'Conflict');
61export const gone = mkResponse(410, 'Gone');
62export const lengthRequired = mkResponse(411, 'Length Required');
63export const preconditionFailed = mkResponse(412, 'Precondition Failed');
64export const payloadTooLarge = mkResponse(413, 'Payload Too Large');
65export const uriTooLong = mkResponse(414, 'URI Too Long');
66export const unsupportedMediaType = mkResponse(415, 'Unsupported Media Type');
67export const rangeNotSatisfiable = mkResponse(416, 'Range Not Satisfiable');
68export const expectationFailed = mkResponse(417, 'Expectation Failed');
69export const imATeapot = mkResponse(418, 'I\'m a teapot');
70export const misdirectedRequest = mkResponse(421, 'Misdirected Request');
71export const unprocessableEntity = mkResponse(422, 'Unprocessable Entity');
72export const locked = mkResponse(423, 'Locked');
73export const failedDependency = mkResponse(424, 'Failed Dependency');
74export const tooEarly = mkResponse(425, 'Too Early');
75export const upgradeRequired = mkResponse(426, 'Upgrade Required');
76export const preconditionRequired = mkResponse(428, 'Precondition Required');
77export const tooManyRequests = mkResponse(429, 'Too Many Requests');
78export const requestHeaderFieldsTooLarge = mkResponse(431, 'Request Header Fields Too Large');
79export const unavailableForLegalReasons = mkResponse(451, 'Unavailable For Legal Reasons');
80export const internalServerError = mkResponse(500, 'Internal Server Error');
81export const notImplemented = mkResponse(501, 'Not Implemented');
82export const badGateway = mkResponse(502, 'Bad Gateway');
83export const serviceUnavailable = mkResponse(503, 'Service Unavailable');
84export const gatewayTimeout = mkResponse(504, 'Gateway Timeout');
85export const httpVersionNotSupported = mkResponse(505, 'HTTP Version Not Supported');
86export const variantAlsoNegotiates = mkResponse(506, 'Variant Also Negotiates');
87export const insufficientStorage = mkResponse(507, 'Insufficient Storage');
88export const loopDetected = mkResponse(508, 'Loop Detected');
89export const notExtended = mkResponse(510, 'Not Extended');
90export const networkAuthenticationRequired = mkResponse(511, 'Network Authentication Required');
91//# sourceMappingURL=index.js.map
\No newline at end of file