@adonisjs/http-server 7.0.0-1 → 7.0.0-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/build/chunk-NC6OWANS.js +4437 -0
  2. package/build/chunk-NC6OWANS.js.map +1 -0
  3. package/build/factories/http_server.d.ts +1 -0
  4. package/build/factories/main.js +332 -14
  5. package/build/factories/main.js.map +1 -0
  6. package/build/index.js +309 -22
  7. package/build/index.js.map +1 -0
  8. package/build/src/define_middleware.d.ts +2 -1
  9. package/build/src/router/lookup_store/main.d.ts +1 -3
  10. package/build/src/router/lookup_store/route_finder.d.ts +5 -1
  11. package/build/src/router/main.d.ts +5 -4
  12. package/build/src/router/resource.d.ts +19 -7
  13. package/build/src/types/main.js +1 -15
  14. package/build/src/types/main.js.map +1 -0
  15. package/build/src/types/middleware.d.ts +3 -1
  16. package/package.json +60 -59
  17. package/build/factories/http_context.js +0 -51
  18. package/build/factories/http_server.js +0 -26
  19. package/build/factories/qs_parser_factory.js +0 -44
  20. package/build/factories/request.js +0 -73
  21. package/build/factories/response.js +0 -77
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.js +0 -65
  24. package/build/src/cookies/client.js +0 -84
  25. package/build/src/cookies/drivers/encrypted.js +0 -36
  26. package/build/src/cookies/drivers/plain.js +0 -33
  27. package/build/src/cookies/drivers/signed.js +0 -36
  28. package/build/src/cookies/parser.js +0 -167
  29. package/build/src/cookies/serializer.js +0 -79
  30. package/build/src/debug.js +0 -10
  31. package/build/src/define_config.js +0 -68
  32. package/build/src/define_middleware.js +0 -35
  33. package/build/src/exception_handler.js +0 -306
  34. package/build/src/exceptions.js +0 -38
  35. package/build/src/helpers.js +0 -105
  36. package/build/src/http_context/local_storage.js +0 -39
  37. package/build/src/http_context/main.js +0 -105
  38. package/build/src/qs.js +0 -25
  39. package/build/src/redirect.js +0 -140
  40. package/build/src/request.js +0 -865
  41. package/build/src/response.js +0 -1208
  42. package/build/src/router/brisk.js +0 -85
  43. package/build/src/router/executor.js +0 -30
  44. package/build/src/router/factories/use_return_value.js +0 -22
  45. package/build/src/router/group.js +0 -207
  46. package/build/src/router/lookup_store/main.js +0 -86
  47. package/build/src/router/lookup_store/route_finder.js +0 -49
  48. package/build/src/router/lookup_store/url_builder.js +0 -209
  49. package/build/src/router/main.js +0 -316
  50. package/build/src/router/matchers.js +0 -36
  51. package/build/src/router/parser.js +0 -17
  52. package/build/src/router/resource.js +0 -216
  53. package/build/src/router/route.js +0 -293
  54. package/build/src/router/store.js +0 -195
  55. package/build/src/server/factories/final_handler.js +0 -30
  56. package/build/src/server/factories/middleware_handler.js +0 -16
  57. package/build/src/server/factories/write_response.js +0 -24
  58. package/build/src/server/main.js +0 -292
  59. package/build/src/types/base.js +0 -9
  60. package/build/src/types/middleware.js +0 -9
  61. package/build/src/types/qs.js +0 -9
  62. package/build/src/types/request.js +0 -9
  63. package/build/src/types/response.js +0 -9
  64. package/build/src/types/route.js +0 -9
  65. package/build/src/types/server.js +0 -9
@@ -1,33 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { base64, MessageBuilder } from '@poppinss/utils';
10
- /**
11
- * Encodes a value into a base64 url encoded string to
12
- * be set as cookie
13
- */
14
- export function pack(value) {
15
- if (value === undefined || value === null) {
16
- return null;
17
- }
18
- return base64.urlEncode(new MessageBuilder().build(value));
19
- }
20
- /**
21
- * Returns true when this `unpack` method of this module can attempt
22
- * to unpack the encode value.
23
- */
24
- export function canUnpack(encodedValue) {
25
- return typeof encodedValue === 'string';
26
- }
27
- /**
28
- * Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
29
- * before calling this method
30
- */
31
- export function unpack(encodedValue) {
32
- return new MessageBuilder().verify(base64.urlDecode(encodedValue, 'utf-8', false));
33
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * Signs a value to be shared as a cookie. The signed output has a
11
- * hash to verify tampering with the original value
12
- */
13
- export function pack(key, value, encryption) {
14
- if (value === undefined || value === null) {
15
- return null;
16
- }
17
- return `s:${encryption.verifier.sign(value, undefined, key)}`;
18
- }
19
- /**
20
- * Returns a boolean, if the unpack method from this module can attempt
21
- * to unpack the signed value.
22
- */
23
- export function canUnpack(signedValue) {
24
- return typeof signedValue === 'string' && signedValue.substring(0, 2) === 's:';
25
- }
26
- /**
27
- * Attempts to unpack the signed value. Make sure to call `canUnpack` before
28
- * calling this method.
29
- */
30
- export function unpack(key, signedValue, encryption) {
31
- const value = signedValue.slice(2);
32
- if (!value) {
33
- return null;
34
- }
35
- return encryption.verifier.unsign(value, key);
36
- }
@@ -1,167 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import cookie from 'cookie';
10
- import { CookieClient } from './client.js';
11
- /**
12
- * Cookie parser parses the HTTP `cookie` header and collects all cookies
13
- * inside an object of `key-value` pair, but doesn't attempt to decrypt
14
- * or unsign or decode the individual values.
15
- *
16
- * The cookie values are lazily decrypted, or unsigned to avoid unncessary
17
- * processing, which infact can be used as a means to burden the server
18
- * by sending too many cookies which even doesn't belongs to the
19
- * server.
20
- */
21
- export class CookieParser {
22
- #client;
23
- /**
24
- * A copy of cached cookies, they are cached during a request after
25
- * initial decoding, unsigning or decrypting.
26
- */
27
- #cachedCookies = {
28
- signedCookies: {},
29
- plainCookies: {},
30
- encryptedCookies: {},
31
- };
32
- /**
33
- * An object of key-value pair collected by parsing
34
- * the request cookie header.
35
- */
36
- #cookies;
37
- constructor(cookieHeader, encryption) {
38
- this.#client = new CookieClient(encryption);
39
- this.#cookies = this.#parse(cookieHeader);
40
- }
41
- /**
42
- * Parses the request `cookie` header
43
- */
44
- #parse(cookieHeader) {
45
- /*
46
- * Set to empty object when cookie header is empty string
47
- */
48
- if (!cookieHeader) {
49
- return {};
50
- }
51
- /*
52
- * Parse and store reference
53
- */
54
- return cookie.parse(cookieHeader);
55
- }
56
- /**
57
- * Attempts to decode a cookie by the name. When calling this method,
58
- * you are assuming that the cookie was just encoded in the first
59
- * place and not signed or encrypted.
60
- */
61
- decode(key, encoded = true) {
62
- /*
63
- * Ignore when initial value is not defined or null
64
- */
65
- const value = this.#cookies[key];
66
- if (value === null || value === undefined) {
67
- return null;
68
- }
69
- /*
70
- * Reference to the cache object. Mainly done to avoid typos,
71
- * since this object is referenced a handful of times inside
72
- * this method.
73
- */
74
- const cache = this.#cachedCookies.plainCookies;
75
- /*
76
- * Return from cache, when already parsed
77
- */
78
- if (cache[key] !== undefined) {
79
- return cache[key];
80
- }
81
- /*
82
- * Attempt to unpack and cache it for future. The value is only
83
- * when value it is not null.
84
- */
85
- const parsed = encoded ? this.#client.decode(key, value) : value;
86
- if (parsed !== null) {
87
- cache[key] = parsed;
88
- }
89
- return parsed;
90
- }
91
- /**
92
- * Attempts to unsign a cookie by the name. When calling this method,
93
- * you are assuming that the cookie was signed in the first place.
94
- */
95
- unsign(key) {
96
- /*
97
- * Ignore when initial value is not defined or null
98
- */
99
- const value = this.#cookies[key];
100
- if (value === null || value === undefined) {
101
- return null;
102
- }
103
- /*
104
- * Reference to the cache object. Mainly done to avoid typos,
105
- * since this object is referenced a handful of times inside
106
- * this method.
107
- */
108
- const cache = this.#cachedCookies.signedCookies;
109
- /*
110
- * Return from cache, when already parsed
111
- */
112
- if (cache[key] !== undefined) {
113
- return cache[key];
114
- }
115
- /*
116
- * Attempt to unpack and cache it for future. The value is only
117
- * when value it is not null.
118
- */
119
- const parsed = this.#client.unsign(key, value);
120
- if (parsed !== null) {
121
- cache[key] = parsed;
122
- }
123
- return parsed;
124
- }
125
- /**
126
- * Attempts to decrypt a cookie by the name. When calling this method,
127
- * you are assuming that the cookie was encrypted in the first place.
128
- */
129
- decrypt(key) {
130
- /*
131
- * Ignore when initial value is not defined or null
132
- */
133
- const value = this.#cookies[key];
134
- if (value === null || value === undefined) {
135
- return null;
136
- }
137
- /*
138
- * Reference to the cache object. Mainly done to avoid typos,
139
- * since this object is referenced a handful of times inside
140
- * this method.
141
- */
142
- const cache = this.#cachedCookies.encryptedCookies;
143
- /*
144
- * Return from cache, when already parsed
145
- */
146
- if (cache[key] !== undefined) {
147
- return cache[key];
148
- }
149
- /*
150
- * Attempt to unpack and cache it for future. The value is only
151
- * when value it is not null.
152
- */
153
- const parsed = this.#client.decrypt(key, value);
154
- if (parsed !== null) {
155
- cache[key] = parsed;
156
- }
157
- return parsed;
158
- }
159
- /**
160
- * Returns an object of cookies key-value pair. Do note, the
161
- * cookies are not decoded, unsigned or decrypted inside this
162
- * list.
163
- */
164
- list() {
165
- return this.#cookies;
166
- }
167
- }
@@ -1,79 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import cookie from 'cookie';
10
- import string from '@poppinss/utils/string';
11
- import { CookieClient } from './client.js';
12
- /**
13
- * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
14
- * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
15
- * and then set them individually using the `set-cookie` header.
16
- */
17
- export class CookieSerializer {
18
- #client;
19
- constructor(encryption) {
20
- this.#client = new CookieClient(encryption);
21
- }
22
- /**
23
- * Serializes the key-value pair to a string, that can be set on the
24
- * `Set-Cookie` header.
25
- */
26
- #serializeAsCookie(key, value, options) {
27
- /**
28
- * Invoked expires method to get the date
29
- */
30
- let expires = options?.expires;
31
- if (typeof expires === 'function') {
32
- expires = expires();
33
- }
34
- /**
35
- * Parse string based max age to seconds
36
- */
37
- let maxAge = options?.maxAge ? string.seconds.parse(options?.maxAge) : undefined;
38
- const parsedOptions = Object.assign({}, options, { maxAge, expires });
39
- return cookie.serialize(key, value, parsedOptions);
40
- }
41
- /**
42
- * Encodes value as a plain cookie. By default, the plain value will be converted
43
- * to a string using "JSON.stringify" method and then encoded as a base64 string.
44
- *
45
- * You can disable encoding of the cookie by setting `options.encoded = false`.
46
- *
47
- * ```ts
48
- * serializer.encode('name', 'virk')
49
- * ```
50
- */
51
- encode(key, value, options) {
52
- const packedValue = options?.encode === false ? value : this.#client.encode(key, value);
53
- if (packedValue === null || packedValue === undefined) {
54
- return null;
55
- }
56
- return this.#serializeAsCookie(key, packedValue, options);
57
- }
58
- /**
59
- * Sign a key-value pair to a signed cookie. The signed value has a
60
- * verification hash attached to it to detect data tampering.
61
- */
62
- sign(key, value, options) {
63
- const packedValue = this.#client.sign(key, value);
64
- if (packedValue === null) {
65
- return null;
66
- }
67
- return this.#serializeAsCookie(key, packedValue, options);
68
- }
69
- /**
70
- * Encrypts a key-value pair to an encrypted cookie.
71
- */
72
- encrypt(key, value, options) {
73
- const packedValue = this.#client.encrypt(key, value);
74
- if (packedValue === null) {
75
- return null;
76
- }
77
- return this.#serializeAsCookie(key, packedValue, options);
78
- }
79
- }
@@ -1,10 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { debuglog } from 'node:util';
10
- export default debuglog('adonisjs:http');
@@ -1,68 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import proxyAddr from 'proxy-addr';
10
- import string from '@poppinss/utils/string';
11
- /**
12
- * Define configuration for the HTTP server
13
- */
14
- export function defineConfig(config) {
15
- const { trustProxy, ...rest } = config;
16
- const normalizedConfig = {
17
- allowMethodSpoofing: false,
18
- trustProxy: proxyAddr.compile('loopback'),
19
- subdomainOffset: 2,
20
- generateRequestId: false,
21
- useAsyncLocalStorage: false,
22
- etag: false,
23
- jsonpCallbackName: 'callback',
24
- cookie: {
25
- maxAge: '2h',
26
- path: '/',
27
- httpOnly: true,
28
- secure: false,
29
- sameSite: false,
30
- },
31
- qs: {
32
- parse: {
33
- depth: 5,
34
- parameterLimit: 1000,
35
- allowSparse: false,
36
- arrayLimit: 20,
37
- comma: true,
38
- },
39
- stringify: {
40
- encode: true,
41
- encodeValuesOnly: false,
42
- arrayFormat: 'indices',
43
- skipNulls: false,
44
- },
45
- },
46
- ...rest,
47
- };
48
- /**
49
- * Normalizing maxAge property on cookies to be a number in
50
- * seconds
51
- */
52
- if (normalizedConfig.cookie.maxAge) {
53
- normalizedConfig.cookie.maxAge = string.seconds.parse(normalizedConfig.cookie.maxAge);
54
- }
55
- /**
56
- * Normalizing trust proxy setting to allow boolean and
57
- * string values
58
- */
59
- if (typeof trustProxy === 'boolean') {
60
- const tpValue = trustProxy;
61
- normalizedConfig.trustProxy = (_, __) => tpValue;
62
- }
63
- else if (typeof trustProxy === 'string') {
64
- const tpValue = trustProxy;
65
- normalizedConfig.trustProxy = proxyAddr.compile(tpValue);
66
- }
67
- return normalizedConfig;
68
- }
@@ -1,35 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { moduleImporter } from '@adonisjs/fold';
10
- /**
11
- * Converts a middleware name and its lazy import to a factory function. The function
12
- * can than later be used to reference the middleware with different arguments
13
- * every time.
14
- */
15
- function middlewareReferenceBuilder(name, middleware) {
16
- const handler = moduleImporter(middleware, 'handle').toHandleMethod();
17
- return function (...args) {
18
- return {
19
- name,
20
- args: args[0],
21
- ...handler,
22
- };
23
- };
24
- }
25
- /**
26
- * Define an collection of named middleware. The collection gets converted
27
- * into a collection of factory functions. Calling the function returns
28
- * a reference to the executable middleware.
29
- */
30
- export function defineNamedMiddleware(collection) {
31
- return Object.keys(collection).reduce((result, key) => {
32
- result[key] = middlewareReferenceBuilder(key, collection[key]);
33
- return result;
34
- }, {});
35
- }