@adonisjs/http-server 6.8.2-5 → 6.8.2-7
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.
- package/README.md +3 -6
- package/build/factories/http_context.d.ts +10 -1
- package/build/factories/http_context.js +27 -0
- package/build/factories/http_server.d.ts +8 -0
- package/build/factories/http_server.js +26 -0
- package/build/factories/main.d.ts +0 -1
- package/build/factories/main.js +8 -0
- package/build/factories/qs_parser_factory.d.ts +10 -1
- package/build/factories/qs_parser_factory.js +18 -0
- package/build/factories/request.d.ts +10 -1
- package/build/factories/request.js +31 -0
- package/build/factories/response.d.ts +10 -1
- package/build/factories/response.js +34 -0
- package/build/factories/router.d.ts +10 -1
- package/build/factories/router.js +25 -0
- package/build/factories/server_factory.d.ts +10 -1
- package/build/factories/server_factory.js +34 -0
- package/build/index.d.ts +0 -1
- package/build/index.js +8 -0
- package/build/src/cookies/client.d.ts +25 -1
- package/build/src/cookies/client.js +42 -0
- package/build/src/cookies/drivers/encrypted.d.ts +12 -1
- package/build/src/cookies/drivers/encrypted.js +20 -0
- package/build/src/cookies/drivers/plain.d.ts +12 -1
- package/build/src/cookies/drivers/plain.js +20 -0
- package/build/src/cookies/drivers/signed.d.ts +12 -1
- package/build/src/cookies/drivers/signed.js +20 -0
- package/build/src/cookies/parser.d.ts +28 -1
- package/build/src/cookies/parser.js +98 -0
- package/build/src/cookies/serializer.d.ts +22 -1
- package/build/src/cookies/serializer.js +40 -0
- package/build/src/debug.d.ts +0 -1
- package/build/src/debug.js +8 -0
- package/build/src/define_config.d.ts +3 -1
- package/build/src/define_config.js +11 -0
- package/build/src/define_middleware.d.ts +5 -1
- package/build/src/define_middleware.js +18 -0
- package/build/src/exception_handler.d.ts +65 -1
- package/build/src/exception_handler.js +95 -0
- package/build/src/exceptions.d.ts +6 -1
- package/build/src/exceptions.js +11 -0
- package/build/src/helpers.d.ts +14 -1
- package/build/src/helpers.js +22 -0
- package/build/src/http_context/local_storage.d.ts +3 -1
- package/build/src/http_context/local_storage.js +25 -0
- package/build/src/http_context/main.d.ts +36 -1
- package/build/src/http_context/main.js +54 -0
- package/build/src/qs.d.ts +4 -1
- package/build/src/qs.js +12 -0
- package/build/src/redirect.d.ts +24 -1
- package/build/src/redirect.js +60 -0
- package/build/src/request.d.ts +466 -1
- package/build/src/request.js +542 -0
- package/build/src/response.d.ts +425 -2
- package/build/src/response.js +608 -7
- package/build/src/router/brisk.d.ts +22 -1
- package/build/src/router/brisk.js +42 -0
- package/build/src/router/executor.d.ts +4 -1
- package/build/src/router/executor.js +12 -0
- package/build/src/router/factories/use_return_value.d.ts +4 -1
- package/build/src/router/factories/use_return_value.js +16 -3
- package/build/src/router/group.d.ts +47 -1
- package/build/src/router/group.js +88 -0
- package/build/src/router/lookup_store/main.d.ts +32 -1
- package/build/src/router/lookup_store/main.js +49 -0
- package/build/src/router/lookup_store/route_finder.d.ts +13 -1
- package/build/src/router/lookup_store/route_finder.js +21 -0
- package/build/src/router/lookup_store/url_builder.d.ts +36 -1
- package/build/src/router/lookup_store/url_builder.js +97 -0
- package/build/src/router/main.d.ts +87 -1
- package/build/src/router/main.js +142 -0
- package/build/src/router/matchers.d.ts +13 -1
- package/build/src/router/matchers.js +21 -0
- package/build/src/router/parser.d.ts +3 -1
- package/build/src/router/parser.js +12 -0
- package/build/src/router/resource.d.ts +28 -1
- package/build/src/router/resource.js +90 -0
- package/build/src/router/route.d.ts +65 -1
- package/build/src/router/route.js +142 -0
- package/build/src/router/store.d.ts +54 -1
- package/build/src/router/store.js +102 -0
- package/build/src/server/factories/final_handler.d.ts +5 -1
- package/build/src/server/factories/final_handler.js +13 -0
- package/build/src/server/factories/middleware_handler.d.ts +3 -1
- package/build/src/server/factories/middleware_handler.js +11 -0
- package/build/src/server/factories/write_response.d.ts +4 -1
- package/build/src/server/factories/write_response.js +12 -0
- package/build/src/server/main.d.ts +48 -1
- package/build/src/server/main.js +128 -0
- package/build/src/types/base.d.ts +12 -1
- package/build/src/types/base.js +8 -0
- package/build/src/types/main.d.ts +0 -1
- package/build/src/types/main.js +8 -0
- package/build/src/types/middleware.d.ts +18 -1
- package/build/src/types/middleware.js +8 -0
- package/build/src/types/qs.d.ts +53 -1
- package/build/src/types/qs.js +8 -0
- package/build/src/types/request.d.ts +32 -1
- package/build/src/types/request.js +8 -0
- package/build/src/types/response.d.ts +27 -1
- package/build/src/types/response.js +8 -0
- package/build/src/types/route.d.ts +87 -1
- package/build/src/types/route.js +8 -0
- package/build/src/types/server.d.ts +35 -1
- package/build/src/types/server.js +8 -0
- package/package.json +43 -70
- package/build/factories/http_context.d.ts.map +0 -1
- package/build/factories/main.d.ts.map +0 -1
- package/build/factories/qs_parser_factory.d.ts.map +0 -1
- package/build/factories/request.d.ts.map +0 -1
- package/build/factories/response.d.ts.map +0 -1
- package/build/factories/router.d.ts.map +0 -1
- package/build/factories/server_factory.d.ts.map +0 -1
- package/build/index.d.ts.map +0 -1
- package/build/src/cookies/client.d.ts.map +0 -1
- package/build/src/cookies/drivers/encrypted.d.ts.map +0 -1
- package/build/src/cookies/drivers/plain.d.ts.map +0 -1
- package/build/src/cookies/drivers/signed.d.ts.map +0 -1
- package/build/src/cookies/parser.d.ts.map +0 -1
- package/build/src/cookies/serializer.d.ts.map +0 -1
- package/build/src/debug.d.ts.map +0 -1
- package/build/src/define_config.d.ts.map +0 -1
- package/build/src/define_middleware.d.ts.map +0 -1
- package/build/src/exception_handler.d.ts.map +0 -1
- package/build/src/exceptions.d.ts.map +0 -1
- package/build/src/helpers.d.ts.map +0 -1
- package/build/src/http_context/local_storage.d.ts.map +0 -1
- package/build/src/http_context/main.d.ts.map +0 -1
- package/build/src/qs.d.ts.map +0 -1
- package/build/src/redirect.d.ts.map +0 -1
- package/build/src/request.d.ts.map +0 -1
- package/build/src/response.d.ts.map +0 -1
- package/build/src/router/brisk.d.ts.map +0 -1
- package/build/src/router/executor.d.ts.map +0 -1
- package/build/src/router/factories/use_return_value.d.ts.map +0 -1
- package/build/src/router/group.d.ts.map +0 -1
- package/build/src/router/lookup_store/main.d.ts.map +0 -1
- package/build/src/router/lookup_store/route_finder.d.ts.map +0 -1
- package/build/src/router/lookup_store/url_builder.d.ts.map +0 -1
- package/build/src/router/main.d.ts.map +0 -1
- package/build/src/router/matchers.d.ts.map +0 -1
- package/build/src/router/parser.d.ts.map +0 -1
- package/build/src/router/resource.d.ts.map +0 -1
- package/build/src/router/route.d.ts.map +0 -1
- package/build/src/router/store.d.ts.map +0 -1
- package/build/src/server/factories/final_handler.d.ts.map +0 -1
- package/build/src/server/factories/middleware_handler.d.ts.map +0 -1
- package/build/src/server/factories/write_response.d.ts.map +0 -1
- package/build/src/server/main.d.ts.map +0 -1
- package/build/src/types/base.d.ts.map +0 -1
- package/build/src/types/main.d.ts.map +0 -1
- package/build/src/types/middleware.d.ts.map +0 -1
- package/build/src/types/qs.d.ts.map +0 -1
- package/build/src/types/request.d.ts.map +0 -1
- package/build/src/types/response.d.ts.map +0 -1
- package/build/src/types/route.d.ts.map +0 -1
- package/build/src/types/server.d.ts.map +0 -1
- package/factories/http_context.ts +0 -73
- package/factories/main.ts +0 -15
- package/factories/qs_parser_factory.ts +0 -54
- package/factories/request.ts +0 -101
- package/factories/response.ts +0 -106
- package/factories/router.ts +0 -61
- package/factories/server_factory.ts +0 -94
- package/index.ts +0 -23
- package/src/cookies/client.ts +0 -98
- package/src/cookies/drivers/encrypted.ts +0 -42
- package/src/cookies/drivers/plain.ts +0 -37
- package/src/cookies/drivers/signed.ts +0 -42
- package/src/cookies/parser.ts +0 -196
- package/src/cookies/serializer.ts +0 -98
- package/src/debug.ts +0 -11
- package/src/define_config.ts +0 -56
- package/src/define_middleware.ts +0 -61
- package/src/exception_handler.ts +0 -290
- package/src/exceptions.ts +0 -55
- package/src/helpers.ts +0 -108
- package/src/http_context/local_storage.ts +0 -50
- package/src/http_context/main.ts +0 -126
- package/src/qs.ts +0 -31
- package/src/redirect.ts +0 -181
- package/src/request.ts +0 -982
- package/src/response.ts +0 -1421
- package/src/router/brisk.ts +0 -113
- package/src/router/executor.ts +0 -36
- package/src/router/factories/use_return_value.ts +0 -26
- package/src/router/group.ts +0 -243
- package/src/router/lookup_store/main.ts +0 -102
- package/src/router/lookup_store/route_finder.ts +0 -60
- package/src/router/lookup_store/url_builder.ts +0 -250
- package/src/router/main.ts +0 -431
- package/src/router/matchers.ts +0 -40
- package/src/router/parser.ts +0 -20
- package/src/router/resource.ts +0 -277
- package/src/router/route.ts +0 -363
- package/src/router/store.ts +0 -239
- package/src/server/factories/final_handler.ts +0 -38
- package/src/server/factories/middleware_handler.ts +0 -23
- package/src/server/factories/write_response.ts +0 -26
- package/src/server/main.ts +0 -356
- package/src/types/base.ts +0 -30
- package/src/types/main.ts +0 -16
- package/src/types/middleware.ts +0 -59
- package/src/types/qs.ts +0 -85
- package/src/types/request.ts +0 -52
- package/src/types/response.ts +0 -57
- package/src/types/route.ts +0 -217
- package/src/types/server.ts +0 -92
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
/**
|
|
3
|
+
* Encrypt a value to be set as cookie
|
|
4
|
+
*/
|
|
2
5
|
export declare function pack(key: string, value: any, encryption: Encryption): null | string;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a boolean, if the unpack method from this module can attempt
|
|
8
|
+
* to unpack encrypted value.
|
|
9
|
+
*/
|
|
3
10
|
export declare function canUnpack(encryptedValue: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
|
|
13
|
+
* Only call this method, when `canUnpack` returns true, otherwise runtime
|
|
14
|
+
* exceptions can be raised.
|
|
15
|
+
*/
|
|
4
16
|
export declare function unpack(key: string, encryptedValue: string, encryption: Encryption): null | any;
|
|
5
|
-
//# sourceMappingURL=encrypted.d.ts.map
|
|
@@ -1,12 +1,32 @@
|
|
|
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
|
+
* Encrypt a value to be set as cookie
|
|
11
|
+
*/
|
|
1
12
|
export function pack(key, value, encryption) {
|
|
2
13
|
if (value === undefined || value === null) {
|
|
3
14
|
return null;
|
|
4
15
|
}
|
|
5
16
|
return `e:${encryption.encrypt(value, undefined, key)}`;
|
|
6
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a boolean, if the unpack method from this module can attempt
|
|
20
|
+
* to unpack encrypted value.
|
|
21
|
+
*/
|
|
7
22
|
export function canUnpack(encryptedValue) {
|
|
8
23
|
return typeof encryptedValue === 'string' && encryptedValue.substring(0, 2) === 'e:';
|
|
9
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
|
|
27
|
+
* Only call this method, when `canUnpack` returns true, otherwise runtime
|
|
28
|
+
* exceptions can be raised.
|
|
29
|
+
*/
|
|
10
30
|
export function unpack(key, encryptedValue, encryption) {
|
|
11
31
|
const value = encryptedValue.slice(2);
|
|
12
32
|
if (!value) {
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a value into a base64 url encoded string to
|
|
3
|
+
* be set as cookie
|
|
4
|
+
*/
|
|
1
5
|
export declare function pack(value: any): null | string;
|
|
6
|
+
/**
|
|
7
|
+
* Returns true when this `unpack` method of this module can attempt
|
|
8
|
+
* to unpack the encode value.
|
|
9
|
+
*/
|
|
2
10
|
export declare function canUnpack(encodedValue: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
|
|
13
|
+
* before calling this method
|
|
14
|
+
*/
|
|
3
15
|
export declare function unpack(encodedValue: string): null | any;
|
|
4
|
-
//# sourceMappingURL=plain.d.ts.map
|
|
@@ -1,13 +1,33 @@
|
|
|
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
|
+
*/
|
|
1
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
|
+
*/
|
|
2
14
|
export function pack(value) {
|
|
3
15
|
if (value === undefined || value === null) {
|
|
4
16
|
return null;
|
|
5
17
|
}
|
|
6
18
|
return base64.urlEncode(new MessageBuilder().build(value));
|
|
7
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns true when this `unpack` method of this module can attempt
|
|
22
|
+
* to unpack the encode value.
|
|
23
|
+
*/
|
|
8
24
|
export function canUnpack(encodedValue) {
|
|
9
25
|
return typeof encodedValue === 'string';
|
|
10
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
|
|
29
|
+
* before calling this method
|
|
30
|
+
*/
|
|
11
31
|
export function unpack(encodedValue) {
|
|
12
32
|
return new MessageBuilder().verify(base64.urlDecode(encodedValue, 'utf-8', false));
|
|
13
33
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
/**
|
|
3
|
+
* Signs a value to be shared as a cookie. The signed output has a
|
|
4
|
+
* hash to verify tampering with the original value
|
|
5
|
+
*/
|
|
2
6
|
export declare function pack(key: string, value: any, encryption: Encryption): null | string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a boolean, if the unpack method from this module can attempt
|
|
9
|
+
* to unpack the signed value.
|
|
10
|
+
*/
|
|
3
11
|
export declare function canUnpack(signedValue: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Attempts to unpack the signed value. Make sure to call `canUnpack` before
|
|
14
|
+
* calling this method.
|
|
15
|
+
*/
|
|
4
16
|
export declare function unpack(key: string, signedValue: string, encryption: Encryption): null | any;
|
|
5
|
-
//# sourceMappingURL=signed.d.ts.map
|
|
@@ -1,12 +1,32 @@
|
|
|
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
|
+
*/
|
|
1
13
|
export function pack(key, value, encryption) {
|
|
2
14
|
if (value === undefined || value === null) {
|
|
3
15
|
return null;
|
|
4
16
|
}
|
|
5
17
|
return `s:${encryption.verifier.sign(value, undefined, key)}`;
|
|
6
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns a boolean, if the unpack method from this module can attempt
|
|
21
|
+
* to unpack the signed value.
|
|
22
|
+
*/
|
|
7
23
|
export function canUnpack(signedValue) {
|
|
8
24
|
return typeof signedValue === 'string' && signedValue.substring(0, 2) === 's:';
|
|
9
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Attempts to unpack the signed value. Make sure to call `canUnpack` before
|
|
28
|
+
* calling this method.
|
|
29
|
+
*/
|
|
10
30
|
export function unpack(key, signedValue, encryption) {
|
|
11
31
|
const value = signedValue.slice(2);
|
|
12
32
|
if (!value) {
|
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
/**
|
|
3
|
+
* Cookie parser parses the HTTP `cookie` header and collects all cookies
|
|
4
|
+
* inside an object of `key-value` pair, but doesn't attempt to decrypt
|
|
5
|
+
* or unsign or decode the individual values.
|
|
6
|
+
*
|
|
7
|
+
* The cookie values are lazily decrypted, or unsigned to avoid unncessary
|
|
8
|
+
* processing, which infact can be used as a means to burden the server
|
|
9
|
+
* by sending too many cookies which even doesn't belongs to the
|
|
10
|
+
* server.
|
|
11
|
+
*/
|
|
2
12
|
export declare class CookieParser {
|
|
3
13
|
#private;
|
|
4
14
|
constructor(cookieHeader: string, encryption: Encryption);
|
|
15
|
+
/**
|
|
16
|
+
* Attempts to decode a cookie by the name. When calling this method,
|
|
17
|
+
* you are assuming that the cookie was just encoded in the first
|
|
18
|
+
* place and not signed or encrypted.
|
|
19
|
+
*/
|
|
5
20
|
decode(key: string, encoded?: boolean): any | null;
|
|
21
|
+
/**
|
|
22
|
+
* Attempts to unsign a cookie by the name. When calling this method,
|
|
23
|
+
* you are assuming that the cookie was signed in the first place.
|
|
24
|
+
*/
|
|
6
25
|
unsign(key: string): null | any;
|
|
26
|
+
/**
|
|
27
|
+
* Attempts to decrypt a cookie by the name. When calling this method,
|
|
28
|
+
* you are assuming that the cookie was encrypted in the first place.
|
|
29
|
+
*/
|
|
7
30
|
decrypt(key: string): null | any;
|
|
31
|
+
/**
|
|
32
|
+
* Returns an object of cookies key-value pair. Do note, the
|
|
33
|
+
* cookies are not decoded, unsigned or decrypted inside this
|
|
34
|
+
* list.
|
|
35
|
+
*/
|
|
8
36
|
list(): Record<string, any>;
|
|
9
37
|
}
|
|
10
|
-
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1,68 +1,166 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import cookie from 'cookie';
|
|
2
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
|
+
*/
|
|
3
21
|
export class CookieParser {
|
|
4
22
|
#client;
|
|
23
|
+
/**
|
|
24
|
+
* A copy of cached cookies, they are cached during a request after
|
|
25
|
+
* initial decoding, unsigning or decrypting.
|
|
26
|
+
*/
|
|
5
27
|
#cachedCookies = {
|
|
6
28
|
signedCookies: {},
|
|
7
29
|
plainCookies: {},
|
|
8
30
|
encryptedCookies: {},
|
|
9
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* An object of key-value pair collected by parsing
|
|
34
|
+
* the request cookie header.
|
|
35
|
+
*/
|
|
10
36
|
#cookies;
|
|
11
37
|
constructor(cookieHeader, encryption) {
|
|
12
38
|
this.#client = new CookieClient(encryption);
|
|
13
39
|
this.#cookies = this.#parse(cookieHeader);
|
|
14
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses the request `cookie` header
|
|
43
|
+
*/
|
|
15
44
|
#parse(cookieHeader) {
|
|
45
|
+
/*
|
|
46
|
+
* Set to empty object when cookie header is empty string
|
|
47
|
+
*/
|
|
16
48
|
if (!cookieHeader) {
|
|
17
49
|
return {};
|
|
18
50
|
}
|
|
51
|
+
/*
|
|
52
|
+
* Parse and store reference
|
|
53
|
+
*/
|
|
19
54
|
return cookie.parse(cookieHeader);
|
|
20
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
|
+
*/
|
|
21
61
|
decode(key, encoded = true) {
|
|
62
|
+
/*
|
|
63
|
+
* Ignore when initial value is not defined or null
|
|
64
|
+
*/
|
|
22
65
|
const value = this.#cookies[key];
|
|
23
66
|
if (value === null || value === undefined) {
|
|
24
67
|
return null;
|
|
25
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
|
+
*/
|
|
26
74
|
const cache = this.#cachedCookies.plainCookies;
|
|
75
|
+
/*
|
|
76
|
+
* Return from cache, when already parsed
|
|
77
|
+
*/
|
|
27
78
|
if (cache[key] !== undefined) {
|
|
28
79
|
return cache[key];
|
|
29
80
|
}
|
|
81
|
+
/*
|
|
82
|
+
* Attempt to unpack and cache it for future. The value is only
|
|
83
|
+
* when value it is not null.
|
|
84
|
+
*/
|
|
30
85
|
const parsed = encoded ? this.#client.decode(key, value) : value;
|
|
31
86
|
if (parsed !== null) {
|
|
32
87
|
cache[key] = parsed;
|
|
33
88
|
}
|
|
34
89
|
return parsed;
|
|
35
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
|
+
*/
|
|
36
95
|
unsign(key) {
|
|
96
|
+
/*
|
|
97
|
+
* Ignore when initial value is not defined or null
|
|
98
|
+
*/
|
|
37
99
|
const value = this.#cookies[key];
|
|
38
100
|
if (value === null || value === undefined) {
|
|
39
101
|
return null;
|
|
40
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
|
+
*/
|
|
41
108
|
const cache = this.#cachedCookies.signedCookies;
|
|
109
|
+
/*
|
|
110
|
+
* Return from cache, when already parsed
|
|
111
|
+
*/
|
|
42
112
|
if (cache[key] !== undefined) {
|
|
43
113
|
return cache[key];
|
|
44
114
|
}
|
|
115
|
+
/*
|
|
116
|
+
* Attempt to unpack and cache it for future. The value is only
|
|
117
|
+
* when value it is not null.
|
|
118
|
+
*/
|
|
45
119
|
const parsed = this.#client.unsign(key, value);
|
|
46
120
|
if (parsed !== null) {
|
|
47
121
|
cache[key] = parsed;
|
|
48
122
|
}
|
|
49
123
|
return parsed;
|
|
50
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
|
+
*/
|
|
51
129
|
decrypt(key) {
|
|
130
|
+
/*
|
|
131
|
+
* Ignore when initial value is not defined or null
|
|
132
|
+
*/
|
|
52
133
|
const value = this.#cookies[key];
|
|
53
134
|
if (value === null || value === undefined) {
|
|
54
135
|
return null;
|
|
55
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
|
+
*/
|
|
56
142
|
const cache = this.#cachedCookies.encryptedCookies;
|
|
143
|
+
/*
|
|
144
|
+
* Return from cache, when already parsed
|
|
145
|
+
*/
|
|
57
146
|
if (cache[key] !== undefined) {
|
|
58
147
|
return cache[key];
|
|
59
148
|
}
|
|
149
|
+
/*
|
|
150
|
+
* Attempt to unpack and cache it for future. The value is only
|
|
151
|
+
* when value it is not null.
|
|
152
|
+
*/
|
|
60
153
|
const parsed = this.#client.decrypt(key, value);
|
|
61
154
|
if (parsed !== null) {
|
|
62
155
|
cache[key] = parsed;
|
|
63
156
|
}
|
|
64
157
|
return parsed;
|
|
65
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
|
+
*/
|
|
66
164
|
list() {
|
|
67
165
|
return this.#cookies;
|
|
68
166
|
}
|
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
2
|
import type { CookieOptions } from '../types/response.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
|
|
5
|
+
* header. You can `encode`, `sign` on `encrypt` cookies using the serializer
|
|
6
|
+
* and then set them individually using the `set-cookie` header.
|
|
7
|
+
*/
|
|
3
8
|
export declare class CookieSerializer {
|
|
4
9
|
#private;
|
|
5
10
|
constructor(encryption: Encryption);
|
|
11
|
+
/**
|
|
12
|
+
* Encodes value as a plain cookie. By default, the plain value will be converted
|
|
13
|
+
* to a string using "JSON.stringify" method and then encoded as a base64 string.
|
|
14
|
+
*
|
|
15
|
+
* You can disable encoding of the cookie by setting `options.encoded = false`.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* serializer.encode('name', 'virk')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
6
21
|
encode(key: string, value: any, options?: Partial<CookieOptions & {
|
|
7
22
|
encode: boolean;
|
|
8
23
|
}>): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Sign a key-value pair to a signed cookie. The signed value has a
|
|
26
|
+
* verification hash attached to it to detect data tampering.
|
|
27
|
+
*/
|
|
9
28
|
sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Encrypts a key-value pair to an encrypted cookie.
|
|
31
|
+
*/
|
|
10
32
|
encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
|
|
11
33
|
}
|
|
12
|
-
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -1,20 +1,53 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import cookie from 'cookie';
|
|
2
10
|
import string from '@poppinss/utils/string';
|
|
3
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
|
+
*/
|
|
4
17
|
export class CookieSerializer {
|
|
5
18
|
#client;
|
|
6
19
|
constructor(encryption) {
|
|
7
20
|
this.#client = new CookieClient(encryption);
|
|
8
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Serializes the key-value pair to a string, that can be set on the
|
|
24
|
+
* `Set-Cookie` header.
|
|
25
|
+
*/
|
|
9
26
|
#serializeAsCookie(key, value, options) {
|
|
27
|
+
/**
|
|
28
|
+
* Invoked expires method to get the date
|
|
29
|
+
*/
|
|
10
30
|
let expires = options?.expires;
|
|
11
31
|
if (typeof expires === 'function') {
|
|
12
32
|
expires = expires();
|
|
13
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse string based max age to seconds
|
|
36
|
+
*/
|
|
14
37
|
let maxAge = options?.maxAge ? string.seconds.parse(options?.maxAge) : undefined;
|
|
15
38
|
const parsedOptions = Object.assign({}, options, { maxAge, expires });
|
|
16
39
|
return cookie.serialize(key, value, parsedOptions);
|
|
17
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
|
+
*/
|
|
18
51
|
encode(key, value, options) {
|
|
19
52
|
const packedValue = options?.encode === false ? value : this.#client.encode(key, value);
|
|
20
53
|
if (packedValue === null || packedValue === undefined) {
|
|
@@ -22,6 +55,10 @@ export class CookieSerializer {
|
|
|
22
55
|
}
|
|
23
56
|
return this.#serializeAsCookie(key, packedValue, options);
|
|
24
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
|
+
*/
|
|
25
62
|
sign(key, value, options) {
|
|
26
63
|
const packedValue = this.#client.sign(key, value);
|
|
27
64
|
if (packedValue === null) {
|
|
@@ -29,6 +66,9 @@ export class CookieSerializer {
|
|
|
29
66
|
}
|
|
30
67
|
return this.#serializeAsCookie(key, packedValue, options);
|
|
31
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Encrypts a key-value pair to an encrypted cookie.
|
|
71
|
+
*/
|
|
32
72
|
encrypt(key, value, options) {
|
|
33
73
|
const packedValue = this.#client.encrypt(key, value);
|
|
34
74
|
if (packedValue === null) {
|
package/build/src/debug.d.ts
CHANGED
package/build/src/debug.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import { debuglog } from 'node:util';
|
|
2
10
|
export default debuglog('adonisjs:http');
|
|
@@ -1,5 +1,16 @@
|
|
|
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
|
+
*/
|
|
1
9
|
import proxyAddr from 'proxy-addr';
|
|
2
10
|
import string from '@poppinss/utils/string';
|
|
11
|
+
/**
|
|
12
|
+
* Define configuration for the HTTP server
|
|
13
|
+
*/
|
|
3
14
|
export function defineConfig(config) {
|
|
4
15
|
const normalizedConfig = {
|
|
5
16
|
allowMethodSpoofing: false,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { LazyImport, UnWrapLazyImport } from './types/base.js';
|
|
2
2
|
import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } from './types/middleware.js';
|
|
3
|
+
/**
|
|
4
|
+
* Define an collection of named middleware. The collection gets converted
|
|
5
|
+
* into a collection of factory functions. Calling the function returns
|
|
6
|
+
* a reference to the executable middleware.
|
|
7
|
+
*/
|
|
3
8
|
export declare function defineNamedMiddleware<NamedMiddleware extends Record<string | number | symbol, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
|
|
4
9
|
name: K;
|
|
5
10
|
args: Args[0];
|
|
6
11
|
} & ParsedGlobalMiddleware; };
|
|
7
|
-
//# sourceMappingURL=define_middleware.d.ts.map
|
|
@@ -1,4 +1,17 @@
|
|
|
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
|
+
*/
|
|
1
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
|
+
*/
|
|
2
15
|
function middlewareReferenceBuilder(name, middleware) {
|
|
3
16
|
const handler = moduleImporter(middleware, 'handle').toHandleMethod();
|
|
4
17
|
return function (...args) {
|
|
@@ -9,6 +22,11 @@ function middlewareReferenceBuilder(name, middleware) {
|
|
|
9
22
|
};
|
|
10
23
|
};
|
|
11
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
|
+
*/
|
|
12
30
|
export function defineNamedMiddleware(collection) {
|
|
13
31
|
return Object.keys(collection).reduce((result, key) => {
|
|
14
32
|
result[key] = middlewareReferenceBuilder(key, collection[key]);
|
|
@@ -1,26 +1,90 @@
|
|
|
1
1
|
import type { Level } from '@adonisjs/logger/types';
|
|
2
2
|
import type { HttpContext } from './http_context/main.js';
|
|
3
3
|
import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
|
|
4
|
+
/**
|
|
5
|
+
* The base HTTP exception handler one can inherit from to handle
|
|
6
|
+
* HTTP exceptions.
|
|
7
|
+
*
|
|
8
|
+
* The HTTP exception handler has support for
|
|
9
|
+
*
|
|
10
|
+
* - Ability to render exceptions by calling the render method on the exception.
|
|
11
|
+
* - Rendering status pages
|
|
12
|
+
* - Pretty printing errors during development
|
|
13
|
+
* - Transforming errors to JSON or HTML using content negotiation
|
|
14
|
+
* - Reporting errors
|
|
15
|
+
*/
|
|
4
16
|
export declare class ExceptionHandler {
|
|
5
17
|
#private;
|
|
18
|
+
/**
|
|
19
|
+
* Whether or not to render debug info. When set to true, the errors
|
|
20
|
+
* will have the complete error stack.
|
|
21
|
+
*/
|
|
6
22
|
protected debug: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether or not to render status pages. When set to true, the unhandled
|
|
25
|
+
* errors with matching status codes will be rendered using a status
|
|
26
|
+
* page.
|
|
27
|
+
*/
|
|
7
28
|
protected renderStatusPages: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A collection of error status code range and the view to render.
|
|
31
|
+
*/
|
|
8
32
|
protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
|
|
33
|
+
/**
|
|
34
|
+
* Renderers for rendering an error.
|
|
35
|
+
*/
|
|
9
36
|
protected renderers: {
|
|
10
37
|
html: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
11
38
|
json: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
12
39
|
json_api: (error: HttpError, ctx: HttpContext) => Promise<void>;
|
|
13
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Enable/disable errors reporting
|
|
43
|
+
*/
|
|
14
44
|
protected reportErrors: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* An array of exception classes to ignore when
|
|
47
|
+
* reporting an error
|
|
48
|
+
*/
|
|
15
49
|
protected ignoreExceptions: any[];
|
|
50
|
+
/**
|
|
51
|
+
* An array of HTTP status codes to ignore when reporting
|
|
52
|
+
* an error
|
|
53
|
+
*/
|
|
16
54
|
protected ignoreStatuses: number[];
|
|
55
|
+
/**
|
|
56
|
+
* An array of error codes to ignore when reporting
|
|
57
|
+
* an error
|
|
58
|
+
*/
|
|
17
59
|
protected ignoreCodes: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Error reporting context
|
|
62
|
+
*/
|
|
18
63
|
protected context(ctx: HttpContext): any;
|
|
64
|
+
/**
|
|
65
|
+
* The format in which the error should be rendered.
|
|
66
|
+
*/
|
|
19
67
|
protected getResponseFormat(ctx: HttpContext): 'html' | 'json' | 'json_api';
|
|
68
|
+
/**
|
|
69
|
+
* Returns the log level for an error based upon the error
|
|
70
|
+
* status code.
|
|
71
|
+
*/
|
|
20
72
|
protected getErrorLogLevel(error: HttpError): Level;
|
|
73
|
+
/**
|
|
74
|
+
* A boolean to control if errors should be rendered with
|
|
75
|
+
* all the available debugging info.
|
|
76
|
+
*/
|
|
21
77
|
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Returns a boolean by checking if an error should be reported.
|
|
80
|
+
*/
|
|
22
81
|
protected shouldReport(error: HttpError): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Reports an error during an HTTP request
|
|
84
|
+
*/
|
|
23
85
|
report(error: unknown, ctx: HttpContext): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Handles the error during the HTTP request.
|
|
88
|
+
*/
|
|
24
89
|
handle(error: unknown, ctx: HttpContext): Promise<any>;
|
|
25
90
|
}
|
|
26
|
-
//# sourceMappingURL=exception_handler.d.ts.map
|