5 TextPlain: 'text/plain',
6 ApplicationForm: 'application/x-www-form-urlencoded',
7 ApplicationJson: 'application/json',
10 // Supported encoding types
11 const EncodingType
= {
18 // Filename suffixes for serving pre-encoded files
19 const EncodingTypeSuffix
= {
20 [EncodingType
.Brotli
]: '.br',
21 [EncodingType
.Gzip
]: '.gz',
22 [EncodingType
.XGzip
]: '.gz',
25 const HTTPStatusCode
= {
28 SwitchingProtocols: 101,
35 NonAuthoritativeInformation: 203,
44 MovedPermanently: 301,
48 UseProxy: 305, // Deprecated, do not use
49 SwitchProxy: 306, // No longer used
50 TemporaryRedirect: 307,
51 PermanentRedirect: 308,
58 MethodNotAllowed: 405,
60 ProxyAuthenticationRequired: 407,
65 PreconditionFailed: 412,
67 RequestEntityTooLarge: 413, // Alternate name
69 UnsupportedMediaType: 415,
70 RangeNotSatisfiable: 416,
71 ExpectationFailed: 417,
73 MisdirectedRequest: 421,
74 UnprocessableContent: 422,
76 FailedDependency: 424,
79 PreconditionRequired: 428,
81 RequestHeaderFieldsTooLarge: 431,
82 UnavailableForLegalReasons: 451,
84 InternalServerError: 500,
87 ServiceUnavailable: 503,
89 HTTPVersionNotSupported: 505,
90 VariantAlsoNegotiates: 506,
91 InsufficientStorage: 507,
94 NetworkAuthenticationRequired: 511,
98 const HTTPStatusMessage
= {
101 101: 'Switching Protocols',
108 203: 'Non-Authoritative Information',
110 205: 'Reset Content',
111 206: 'Partial Content',
113 208: 'Already Reported',
116 300: 'Multiple Choices',
117 301: 'Moved Permanently',
123 307: 'Temporary Redirect',
124 308: 'Permanent Redirect',
128 402: 'Payment Required',
130 '403.zalgo': 'F̦̩̫̼͔̫͓̃ͤ̈̆̀͑o̖̟͙̫̯̗̳̽ͦ̆́ͨr̩͉̰̗͉b̬̂͘į̟̬̓d͂͗҉̟͈̜͙ͅd͎̜̺̝͇͑̒̋̾ë̴̳̺͓̦̘́ͮ̈́ǹ͈̦̫̙',
132 405: 'Method Not Allowed',
133 406: 'Not Acceptable',
134 407: 'Proxy Authentication Required',
135 408: 'Request Timeout',
138 411: 'Length Required',
139 412: 'Precondition Failed',
140 413: 'Content Too Large',
142 415: 'Unsupported Media Type',
143 416: 'Range Not Satisfiable',
144 417: 'Expectation Failed',
145 418: 'I\'m A Teapot',
146 421: 'Misdirected Request',
147 422: 'Unprocessable Content',
149 424: 'Failed Dependency',
151 426: 'Upgrade Required',
152 428: 'Precondition Required',
153 429: 'Too Many Requests',
154 431: 'Request Header Fields Too Large',
155 451: 'Unavailable For Legal Reasons',
157 500: 'Internal Server Error',
158 501: 'Not Implemented',
160 503: 'Service Unavailable',
161 504: 'Gateway Timeout',
162 505: 'HTTP Version Not Supported',
163 506: 'Variant Also Negotiates',
164 507: 'Insufficient Storage',
165 508: 'Loop Detected',
167 511: 'Network Authentication Required',
171 function errorResponseGenerator () {
172 return Object
.fromEntries(
173 Object
.entries(HTTPStatusCode
).map(([name
, statusCode
]) => {
174 const errorMessage
= HTTPStatusMessage
[statusCode
]; // eslint-disable-line security/detect-object-injection
175 // istanbul ignore next
177 throw new Error(`missing HTTPStatusMessage for ${statusCode} from HTTPStatusCode ${name}`);
179 return [name
, { statusCode
, errorMessage
}];
183 const ErrorResponse
= errorResponseGenerator();
185 const ErrorResponseProxy
= new Proxy(ErrorResponse
, {
186 get: (target
, property
) => {
187 if (property
in target
) {
188 return target
[property
]; // eslint-disable-line security/detect-object-injection
190 const statusCode
= HTTPStatusCode
.InternalServerError
;
191 const errorMessage
= HTTPStatusMessage
[statusCode
]; // eslint-disable-line security/detect-object-injection
192 const details
= [`undefined error response '${property}'`];
193 return { statusCode
, errorMessage
, details
};
200 AcceptEncoding: 'Accept-Encoding',
201 CacheControl: 'Cache-Control',
202 ContentEncoding: 'Content-Encoding',
203 ContentLength: 'Content-Length',
204 ContentType: 'Content-Type',
207 IfModifiedSince: 'If-Modified-Since',
208 IfNoneMatch: 'If-None-Match',
209 LastModified: 'Last-Modified',
210 Location: 'Location',
211 RequestId: 'Request-ID',
212 SetCookie: 'Set-Cookie',
214 XCorrelationId: 'X-Correlation-ID',
215 XForwardedFor: 'X-Forwarded-For',
216 XForwardedProto: 'X-Forwarded-Proto',
217 XRealIP: 'X-Real-IP',
218 XRequestId: 'X-Request-ID',
225 ErrorResponse: ErrorResponseProxy
,