support maximum request body size
[squeep-api-dingus] / lib / enum.js
1 'use strict';
2
3
4 const ContentType = {
5 TextHTML: 'text/html',
6 TextPlain: 'text/plain',
7 ApplicationForm: 'application/x-www-form-urlencoded',
8 ApplicationJson: 'application/json',
9 };
10
11 // Supported encoding types
12 const EncodingType = {
13 Brotli: 'br',
14 Gzip: 'gzip',
15 XGzip: 'x-gzip',
16 Identity: 'identity',
17 };
18
19 // Filename suffixes for serving pre-encoded files
20 const EncodingTypeSuffix = {
21 [EncodingType.Brotli]: '.br',
22 [EncodingType.Gzip]: '.gz',
23 [EncodingType.XGzip]: '.gz',
24 };
25
26 const ErrorResponse = {
27 BadRequest: {
28 statusCode: 400,
29 errorMessage: 'Bad Request',
30 },
31 Unauthorized: {
32 statusCode: 401,
33 errorMessage: 'Unauthorized',
34 },
35 Forbidden: {
36 statusCode: 403,
37 errorMessage: 'Forbidden',
38 },
39 ReallyForbidden: {
40 statusCode: 403,
41 errorMessage: 'F̦̩̫̼͔̫͓̃ͤ̈̆̀͑o̖̟͙̫̯̗̳̽ͦ̆́ͨr̩͉̰̗͉b̬̂͘į̟̬̓d͂͗҉̟͈̜͙ͅd͎̜̺̝͇͑̒̋̾ë̴̳̺͓̦̘́ͮ̈́ǹ͈̦̫̙',
42 },
43 NotFound: {
44 statusCode: 404,
45 errorMessage: 'Not Found',
46 },
47 MethodNotAllowed: {
48 statusCode: 405,
49 errorMessage: 'Method Not Allowed',
50 },
51 NotAcceptable: {
52 statusCode: 406,
53 errorMessage: 'Not Acceptable',
54 },
55 Gone: {
56 statusCode: 410,
57 errorMessage: 'Gone',
58 },
59 RequestEntityTooLarge: {
60 statusCode: 413,
61 errorMessage: 'Request Entity Too Large',
62 },
63 UnsupportedMediaType: {
64 statusCode: 415,
65 errorMessage: 'Unsupported Media Type',
66 },
67 InternalServerError: {
68 statusCode: 500,
69 errorMessage: 'Internal Server Error',
70 },
71 };
72
73 const ErrorResponseDefaultProxy = new Proxy(ErrorResponse, {
74 get: (target, property) => {
75 // eslint-disable-next-line security/detect-object-injection
76 return (property in target) ? target[property] : {
77 errorMessage: `undefined error response '${property}'`,
78 };
79 },
80 });
81
82 const Header = {
83 Accept: 'Accept',
84 AcceptEncoding: 'Accept-Encoding',
85 CacheControl: 'Cache-Control',
86 ContentEncoding: 'Content-Encoding',
87 ContentLength: 'Content-Length',
88 ContentType: 'Content-Type',
89 ETag: 'ETag',
90 IfModifiedSince: 'If-Modified-Since',
91 IfNoneMatch: 'If-None-Match',
92 LastModified: 'Last-Modified',
93 Location: 'Location',
94 RequestId: 'Request-ID',
95 Vary: 'Vary',
96 XCorrelationId: 'X-Correlation-ID',
97 XForwardedFor: 'X-Forwarded-For',
98 XForwardedProto: 'X-Forwarded-Proto',
99 XRealIP: 'X-Real-IP',
100 XRequestId: 'X-Request-ID',
101 };
102
103 module.exports = {
104 ContentType,
105 EncodingType,
106 EncodingTypeSuffix,
107 ErrorResponse: ErrorResponseDefaultProxy,
108 Header,
109 };