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',
172 * Build an object mapping known http status identifiers to their code and descriptive string.
173 * @returns {object} status mappings
175 function errorResponseGenerator () {
176 return Object
.fromEntries(
177 Object
.entries(HTTPStatusCode
).map(([name
, statusCode
]) => {
178 const errorMessage
= HTTPStatusMessage
[statusCode
]; // eslint-disable-line security/detect-object-injection
179 // istanbul ignore next
181 throw new Error(`missing HTTPStatusMessage for ${statusCode} from HTTPStatusCode ${name}`);
183 return [name
, { statusCode
, errorMessage
}];
187 const ErrorResponse
= errorResponseGenerator();
189 const ErrorResponseProxy
= new Proxy(ErrorResponse
, {
190 get: (target
, property
) => {
191 if (property
in target
) {
192 return target
[property
]; // eslint-disable-line security/detect-object-injection
194 const statusCode
= HTTPStatusCode
.InternalServerError
;
195 const errorMessage
= HTTPStatusMessage
[statusCode
]; // eslint-disable-line security/detect-object-injection
196 const details
= [`undefined error response '${property}'`];
197 return { statusCode
, errorMessage
, details
};
204 AcceptEncoding: 'Accept-Encoding',
205 CacheControl: 'Cache-Control',
206 ContentEncoding: 'Content-Encoding',
207 ContentLength: 'Content-Length',
208 ContentType: 'Content-Type',
211 IfModifiedSince: 'If-Modified-Since',
212 IfNoneMatch: 'If-None-Match',
213 LastModified: 'Last-Modified',
214 Location: 'Location',
215 RequestId: 'Request-ID',
216 SetCookie: 'Set-Cookie',
218 XCorrelationId: 'X-Correlation-ID',
219 XForwardedFor: 'X-Forwarded-For',
220 XForwardedProto: 'X-Forwarded-Proto',
221 XRealIP: 'X-Real-IP',
222 XRequestId: 'X-Request-ID',
229 ErrorResponse: ErrorResponseProxy
,