@adonisjs/http-server 5.11.0 → 6.0.0-0

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 (169) hide show
  1. package/README.md +15 -38
  2. package/build/index.d.ts +16 -0
  3. package/build/index.js +16 -0
  4. package/build/src/cookies/client.d.ts +12 -0
  5. package/build/src/cookies/client.js +42 -0
  6. package/build/src/cookies/drivers/encrypted.d.ts +4 -0
  7. package/build/src/cookies/drivers/encrypted.js +16 -0
  8. package/build/src/cookies/drivers/plain.d.ts +3 -0
  9. package/build/src/cookies/drivers/plain.js +13 -0
  10. package/build/src/cookies/drivers/signed.d.ts +4 -0
  11. package/build/src/cookies/drivers/signed.js +16 -0
  12. package/build/src/cookies/parser.d.ts +9 -0
  13. package/build/src/cookies/parser.js +69 -0
  14. package/build/src/cookies/serializer.d.ts +11 -0
  15. package/build/src/cookies/serializer.js +39 -0
  16. package/build/src/debug.d.ts +3 -0
  17. package/build/src/debug.js +2 -0
  18. package/build/src/define_config.d.ts +2 -0
  19. package/build/src/define_config.js +40 -0
  20. package/build/src/define_middleware.d.ts +4 -0
  21. package/build/src/define_middleware.js +6 -0
  22. package/build/src/exceptions/abort_exception.d.ts +5 -0
  23. package/build/src/exceptions/abort_exception.js +6 -0
  24. package/build/src/exceptions/cannot_lookup_route.d.ts +5 -0
  25. package/build/src/exceptions/cannot_lookup_route.js +5 -0
  26. package/build/src/exceptions/http_exception.d.ts +6 -0
  27. package/build/src/exceptions/http_exception.js +20 -0
  28. package/build/src/exceptions/route_not_found.d.ts +5 -0
  29. package/build/src/exceptions/route_not_found.js +5 -0
  30. package/build/src/helpers.d.ts +6 -67
  31. package/build/src/helpers.js +13 -168
  32. package/build/src/http_context/local_storage.d.ts +9 -0
  33. package/build/src/http_context/local_storage.js +14 -0
  34. package/build/src/http_context/main.d.ts +20 -0
  35. package/build/src/http_context/main.js +49 -0
  36. package/build/src/middleware/store.d.ts +11 -0
  37. package/build/src/middleware/store.js +33 -0
  38. package/build/src/qs.d.ts +7 -0
  39. package/build/src/qs.js +13 -0
  40. package/build/src/redirect.d.ts +18 -0
  41. package/build/src/redirect.js +80 -0
  42. package/build/src/request.d.ts +81 -0
  43. package/build/src/request.js +315 -0
  44. package/build/src/response.d.ts +108 -0
  45. package/build/src/response.js +587 -0
  46. package/build/src/router/brisk.d.ts +18 -0
  47. package/build/src/router/brisk.js +35 -0
  48. package/build/src/router/executor.d.ts +4 -0
  49. package/build/src/router/executor.js +16 -0
  50. package/build/src/router/group.d.ts +19 -0
  51. package/build/src/router/group.js +117 -0
  52. package/build/src/router/lookup_store/main.d.ts +17 -0
  53. package/build/src/router/lookup_store/main.js +37 -0
  54. package/build/src/router/lookup_store/route_finder.d.ts +8 -0
  55. package/build/src/router/lookup_store/route_finder.js +28 -0
  56. package/build/src/router/lookup_store/url_builder.d.ts +16 -0
  57. package/build/src/router/lookup_store/url_builder.js +111 -0
  58. package/build/src/router/main.d.ts +36 -0
  59. package/build/src/router/main.js +161 -0
  60. package/build/src/router/matchers.d.ts +14 -0
  61. package/build/src/router/matchers.js +15 -0
  62. package/build/src/router/resource.d.ts +27 -0
  63. package/build/src/router/resource.js +124 -0
  64. package/build/src/router/route.d.ts +28 -0
  65. package/build/src/router/route.js +135 -0
  66. package/build/src/router/store.d.ts +12 -0
  67. package/build/src/router/store.js +87 -0
  68. package/build/src/server/factories/final_handler.d.ts +4 -0
  69. package/build/src/server/factories/final_handler.js +17 -0
  70. package/build/src/server/factories/middleware_handler.d.ts +5 -0
  71. package/build/src/server/factories/middleware_handler.js +5 -0
  72. package/build/src/server/factories/use_return_value.d.ts +2 -0
  73. package/build/src/server/factories/use_return_value.js +9 -0
  74. package/build/src/server/factories/write_response.d.ts +2 -0
  75. package/build/src/server/factories/write_response.js +12 -0
  76. package/build/src/server/main.d.ts +23 -0
  77. package/build/src/server/main.js +124 -0
  78. package/build/src/types/base.d.ts +5 -0
  79. package/build/src/types/base.js +1 -0
  80. package/build/src/types/middleware.d.ts +14 -0
  81. package/build/src/types/middleware.js +1 -0
  82. package/build/src/types/qs.d.ts +15 -0
  83. package/build/src/types/qs.js +1 -0
  84. package/build/src/types/request.d.ts +7 -0
  85. package/build/src/types/request.js +1 -0
  86. package/build/src/types/response.d.ts +18 -0
  87. package/build/src/types/response.js +1 -0
  88. package/build/src/types/route.d.ts +74 -0
  89. package/build/src/types/route.js +1 -0
  90. package/build/src/types/server.d.ts +13 -0
  91. package/build/src/types/server.js +1 -0
  92. package/package.json +98 -96
  93. package/build/adonis-typings/container.d.ts +0 -24
  94. package/build/adonis-typings/container.js +0 -8
  95. package/build/adonis-typings/context.d.ts +0 -73
  96. package/build/adonis-typings/context.js +0 -8
  97. package/build/adonis-typings/cookie-client.d.ts +0 -34
  98. package/build/adonis-typings/cookie-client.js +0 -8
  99. package/build/adonis-typings/http-server.d.ts +0 -98
  100. package/build/adonis-typings/http-server.js +0 -8
  101. package/build/adonis-typings/index.d.ts +0 -16
  102. package/build/adonis-typings/index.js +0 -16
  103. package/build/adonis-typings/middleware.d.ts +0 -95
  104. package/build/adonis-typings/middleware.js +0 -8
  105. package/build/adonis-typings/request.d.ts +0 -556
  106. package/build/adonis-typings/request.js +0 -8
  107. package/build/adonis-typings/response.d.ts +0 -438
  108. package/build/adonis-typings/response.js +0 -8
  109. package/build/adonis-typings/route.d.ts +0 -559
  110. package/build/adonis-typings/route.js +0 -8
  111. package/build/exceptions.json +0 -110
  112. package/build/providers/HttpServerProvider.d.ts +0 -46
  113. package/build/providers/HttpServerProvider.js +0 -100
  114. package/build/src/Cookie/Client/index.d.ts +0 -39
  115. package/build/src/Cookie/Client/index.js +0 -108
  116. package/build/src/Cookie/Drivers/Encrypted.d.ts +0 -24
  117. package/build/src/Cookie/Drivers/Encrypted.js +0 -42
  118. package/build/src/Cookie/Drivers/Plain.d.ts +0 -23
  119. package/build/src/Cookie/Drivers/Plain.js +0 -40
  120. package/build/src/Cookie/Drivers/Signed.d.ts +0 -24
  121. package/build/src/Cookie/Drivers/Signed.js +0 -42
  122. package/build/src/Cookie/Parser/index.d.ts +0 -61
  123. package/build/src/Cookie/Parser/index.js +0 -174
  124. package/build/src/Cookie/Serializer/index.d.ts +0 -44
  125. package/build/src/Cookie/Serializer/index.js +0 -88
  126. package/build/src/Exceptions/HttpException.d.ts +0 -20
  127. package/build/src/Exceptions/HttpException.js +0 -36
  128. package/build/src/Exceptions/RouterException.d.ts +0 -36
  129. package/build/src/Exceptions/RouterException.js +0 -76
  130. package/build/src/HttpContext/LocalStorage/index.d.ts +0 -24
  131. package/build/src/HttpContext/LocalStorage/index.js +0 -28
  132. package/build/src/HttpContext/index.d.ts +0 -90
  133. package/build/src/HttpContext/index.js +0 -181
  134. package/build/src/MiddlewareStore/index.d.ts +0 -92
  135. package/build/src/MiddlewareStore/index.js +0 -133
  136. package/build/src/Redirect/index.d.ts +0 -71
  137. package/build/src/Redirect/index.js +0 -139
  138. package/build/src/Request/index.d.ts +0 -619
  139. package/build/src/Request/index.js +0 -862
  140. package/build/src/Response/index.d.ts +0 -412
  141. package/build/src/Response/index.js +0 -1010
  142. package/build/src/Router/BriskRoute.d.ts +0 -53
  143. package/build/src/Router/BriskRoute.js +0 -74
  144. package/build/src/Router/Group.d.ts +0 -101
  145. package/build/src/Router/Group.js +0 -165
  146. package/build/src/Router/LookupStore.d.ts +0 -122
  147. package/build/src/Router/LookupStore.js +0 -264
  148. package/build/src/Router/Matchers.d.ts +0 -31
  149. package/build/src/Router/Matchers.js +0 -43
  150. package/build/src/Router/Resource.d.ts +0 -95
  151. package/build/src/Router/Resource.js +0 -182
  152. package/build/src/Router/Route.d.ts +0 -138
  153. package/build/src/Router/Route.js +0 -204
  154. package/build/src/Router/Store.d.ts +0 -93
  155. package/build/src/Router/Store.js +0 -211
  156. package/build/src/Router/index.d.ts +0 -142
  157. package/build/src/Router/index.js +0 -333
  158. package/build/src/Server/ExceptionManager/index.d.ts +0 -49
  159. package/build/src/Server/ExceptionManager/index.js +0 -96
  160. package/build/src/Server/Hooks/index.d.ts +0 -43
  161. package/build/src/Server/Hooks/index.js +0 -77
  162. package/build/src/Server/PreCompiler/index.d.ts +0 -60
  163. package/build/src/Server/PreCompiler/index.js +0 -141
  164. package/build/src/Server/RequestHandler/index.d.ts +0 -39
  165. package/build/src/Server/RequestHandler/index.js +0 -87
  166. package/build/src/Server/index.d.ts +0 -90
  167. package/build/src/Server/index.js +0 -175
  168. package/build/standalone.d.ts +0 -14
  169. package/build/standalone.js +0 -23
package/README.md CHANGED
@@ -1,48 +1,25 @@
1
- <div align="center">
2
- <img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
3
- </div>
1
+ # @adonisjs/http-server
4
2
 
5
3
  <br />
6
4
 
7
- <div align="center">
8
- <h3>AdonisJS HTTP Server</h3>
9
- <p>A fully featured HTTP server with first class support for <strong>Route groups</strong>, <strong>Sub-domain routing</strong>, <strong>Middleware</strong> and <strong>Cookies</strong>.</p>
10
- </div>
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
11
6
 
12
- <br />
7
+ ## Introduction
8
+ Implementation of HTTP server used by AdonisJS. The package ships with a powerful **Router**, **Middleware pipeline**, helpers to create plain and signed URL for registered routes and much more.
13
9
 
14
- <div align="center">
10
+ ## Official Documentation
11
+ The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/context)
15
12
 
16
- [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
13
+ ## Contributing
14
+ One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
15
+
16
+ We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
17
+
18
+ ## Code of Conduct
19
+ In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
17
20
 
18
- </div>
19
-
20
- <div align="center">
21
- <h3>
22
- <a href="https://adonisjs.com">
23
- Website
24
- </a>
25
- <span> | </span>
26
- <a href="https://docs.adonisjs.com/guides/context">
27
- Guides
28
- </a>
29
- <span> | </span>
30
- <a href="CONTRIBUTING.md">
31
- Contributing
32
- </a>
33
- <span> | </span>
34
- <a href="benchmarks.md">
35
- Benchmarks
36
- </a>
37
- </h3>
38
- </div>
39
-
40
- <div align="center">
41
- <sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
42
- </div>
43
-
44
- [appveyor-image]: https://img.shields.io/appveyor/ci/thetutlage/http-server/master.svg?style=for-the-badge&logo=appveyor
45
- [appveyor-url]: https://ci.appveyor.com/project/thetutlage/http-server "appveyor"
21
+ ## License
22
+ AdonisJS HTTP server is open-sourced software licensed under the [MIT license](LICENSE.md).
46
23
 
47
24
  [gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/http-server/test?style=for-the-badge
48
25
  [gh-workflow-url]: https://github.com/adonisjs/http-server/actions/workflows/test.yml "Github action"
@@ -0,0 +1,16 @@
1
+ export { Request } from './src/request.js';
2
+ export { Response } from './src/response.js';
3
+ export { Redirect } from './src/redirect.js';
4
+ export { Server } from './src/server/main.js';
5
+ export { Router } from './src/router/main.js';
6
+ export { Route } from './src/router/route.js';
7
+ export { RouteGroup } from './src/router/group.js';
8
+ export { defineConfig } from './src/define_config.js';
9
+ export { RouteResource } from './src/router/resource.js';
10
+ export { BriskRoute } from './src/router/brisk.js';
11
+ export { HttpContext } from './src/http_context/main.js';
12
+ export { HttpException } from './src/exceptions/http_exception.js';
13
+ export { AbortException } from './src/exceptions/abort_exception.js';
14
+ export { RouteNotFoundException } from './src/exceptions/route_not_found.js';
15
+ export { CannotLookupRouteException } from './src/exceptions/cannot_lookup_route.js';
16
+ export { defineMiddleware, defineNamedMiddleware } from './src/define_middleware.js';
package/build/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export { Request } from './src/request.js';
2
+ export { Response } from './src/response.js';
3
+ export { Redirect } from './src/redirect.js';
4
+ export { Server } from './src/server/main.js';
5
+ export { Router } from './src/router/main.js';
6
+ export { Route } from './src/router/route.js';
7
+ export { RouteGroup } from './src/router/group.js';
8
+ export { defineConfig } from './src/define_config.js';
9
+ export { RouteResource } from './src/router/resource.js';
10
+ export { BriskRoute } from './src/router/brisk.js';
11
+ export { HttpContext } from './src/http_context/main.js';
12
+ export { HttpException } from './src/exceptions/http_exception.js';
13
+ export { AbortException } from './src/exceptions/abort_exception.js';
14
+ export { RouteNotFoundException } from './src/exceptions/route_not_found.js';
15
+ export { CannotLookupRouteException } from './src/exceptions/cannot_lookup_route.js';
16
+ export { defineMiddleware, defineNamedMiddleware } from './src/define_middleware.js';
@@ -0,0 +1,12 @@
1
+ import type Encryption from '@adonisjs/encryption';
2
+ export declare class CookieClient {
3
+ #private;
4
+ constructor(encryption: Encryption);
5
+ encrypt(key: string, value: any): string | null;
6
+ sign(key: string, value: any): string | null;
7
+ encode(_: string, value: any): string | null;
8
+ unsign(key: string, value: string): any;
9
+ decrypt(key: string, value: string): any;
10
+ decode(_: string, value: string): any;
11
+ parse(key: string, value: any): any;
12
+ }
@@ -0,0 +1,42 @@
1
+ import * as plainCookiesDriver from './drivers/plain.js';
2
+ import * as signedCookiesDriver from './drivers/signed.js';
3
+ import * as encryptedCookiesDriver from './drivers/encrypted.js';
4
+ export class CookieClient {
5
+ #encryption;
6
+ constructor(encryption) {
7
+ this.#encryption = encryption;
8
+ }
9
+ encrypt(key, value) {
10
+ return encryptedCookiesDriver.pack(key, value, this.#encryption);
11
+ }
12
+ sign(key, value) {
13
+ return signedCookiesDriver.pack(key, value, this.#encryption);
14
+ }
15
+ encode(_, value) {
16
+ return plainCookiesDriver.pack(value);
17
+ }
18
+ unsign(key, value) {
19
+ return signedCookiesDriver.canUnpack(value)
20
+ ? signedCookiesDriver.unpack(key, value, this.#encryption)
21
+ : null;
22
+ }
23
+ decrypt(key, value) {
24
+ return encryptedCookiesDriver.canUnpack(value)
25
+ ? encryptedCookiesDriver.unpack(key, value, this.#encryption)
26
+ : null;
27
+ }
28
+ decode(_, value) {
29
+ return plainCookiesDriver.canUnpack(value) ? plainCookiesDriver.unpack(value) : null;
30
+ }
31
+ parse(key, value) {
32
+ if (signedCookiesDriver.canUnpack(value)) {
33
+ return signedCookiesDriver.unpack(key, value, this.#encryption);
34
+ }
35
+ if (encryptedCookiesDriver.canUnpack(value)) {
36
+ return encryptedCookiesDriver.unpack(key, value, this.#encryption);
37
+ }
38
+ if (plainCookiesDriver.canUnpack(value)) {
39
+ return plainCookiesDriver.unpack(value);
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,4 @@
1
+ import type Encryption from '@adonisjs/encryption';
2
+ export declare function pack(key: string, value: any, encryption: Encryption): null | string;
3
+ export declare function canUnpack(encryptedValue: string): boolean;
4
+ export declare function unpack(key: string, encryptedValue: string, encryption: Encryption): null | any;
@@ -0,0 +1,16 @@
1
+ export function pack(key, value, encryption) {
2
+ if (value === undefined || value === null) {
3
+ return null;
4
+ }
5
+ return `e:${encryption.encrypt(value, undefined, key)}`;
6
+ }
7
+ export function canUnpack(encryptedValue) {
8
+ return typeof encryptedValue === 'string' && encryptedValue.substring(0, 2) === 'e:';
9
+ }
10
+ export function unpack(key, encryptedValue, encryption) {
11
+ const value = encryptedValue.slice(2);
12
+ if (!value) {
13
+ return null;
14
+ }
15
+ return encryption.decrypt(value, key);
16
+ }
@@ -0,0 +1,3 @@
1
+ export declare function pack(value: any): null | string;
2
+ export declare function canUnpack(encodedValue: string): boolean;
3
+ export declare function unpack(encodedValue: string): null | any;
@@ -0,0 +1,13 @@
1
+ import { base64, MessageBuilder } from '@poppinss/utils';
2
+ export function pack(value) {
3
+ if (value === undefined || value === null) {
4
+ return null;
5
+ }
6
+ return base64.urlEncode(new MessageBuilder().build(value));
7
+ }
8
+ export function canUnpack(encodedValue) {
9
+ return typeof encodedValue === 'string';
10
+ }
11
+ export function unpack(encodedValue) {
12
+ return new MessageBuilder().verify(base64.urlDecode(encodedValue, 'utf-8', false));
13
+ }
@@ -0,0 +1,4 @@
1
+ import type Encryption from '@adonisjs/encryption';
2
+ export declare function pack(key: string, value: any, encryption: Encryption): null | string;
3
+ export declare function canUnpack(signedValue: string): boolean;
4
+ export declare function unpack(key: string, signedValue: string, encryption: Encryption): null | any;
@@ -0,0 +1,16 @@
1
+ export function pack(key, value, encryption) {
2
+ if (value === undefined || value === null) {
3
+ return null;
4
+ }
5
+ return `s:${encryption.verifier.sign(value, undefined, key)}`;
6
+ }
7
+ export function canUnpack(signedValue) {
8
+ return typeof signedValue === 'string' && signedValue.substring(0, 2) === 's:';
9
+ }
10
+ export function unpack(key, signedValue, encryption) {
11
+ const value = signedValue.slice(2);
12
+ if (!value) {
13
+ return null;
14
+ }
15
+ return encryption.verifier.unsign(value, key);
16
+ }
@@ -0,0 +1,9 @@
1
+ import type Encryption from '@adonisjs/encryption';
2
+ export declare class CookieParser {
3
+ #private;
4
+ constructor(cookieHeader: string, encryption: Encryption);
5
+ decode(key: string, encoded?: boolean): any | null;
6
+ unsign(key: string): null | any;
7
+ decrypt(key: string): null | any;
8
+ list(): Record<string, any>;
9
+ }
@@ -0,0 +1,69 @@
1
+ import cookie from 'cookie';
2
+ import { CookieClient } from './client.js';
3
+ export class CookieParser {
4
+ #client;
5
+ #cachedCookies = {
6
+ signedCookies: {},
7
+ plainCookies: {},
8
+ encryptedCookies: {},
9
+ };
10
+ #cookies;
11
+ constructor(cookieHeader, encryption) {
12
+ this.#client = new CookieClient(encryption);
13
+ this.#cookies = this.#parse(cookieHeader);
14
+ }
15
+ #parse(cookieHeader) {
16
+ if (!cookieHeader) {
17
+ return {};
18
+ }
19
+ return cookie.parse(cookieHeader);
20
+ }
21
+ decode(key, encoded = true) {
22
+ const value = this.#cookies[key];
23
+ if (value === null || value === undefined) {
24
+ return null;
25
+ }
26
+ const cache = this.#cachedCookies.plainCookies;
27
+ if (cache[key] !== undefined) {
28
+ return cache[key];
29
+ }
30
+ const parsed = encoded ? this.#client.decode(key, value) : value;
31
+ if (parsed !== null) {
32
+ cache[key] = parsed;
33
+ }
34
+ return parsed;
35
+ }
36
+ unsign(key) {
37
+ const value = this.#cookies[key];
38
+ if (value === null || value === undefined) {
39
+ return null;
40
+ }
41
+ const cache = this.#cachedCookies.signedCookies;
42
+ if (cache[key] !== undefined) {
43
+ return cache[key];
44
+ }
45
+ const parsed = this.#client.unsign(key, value);
46
+ if (parsed !== null) {
47
+ cache[key] = parsed;
48
+ }
49
+ return parsed;
50
+ }
51
+ decrypt(key) {
52
+ const value = this.#cookies[key];
53
+ if (value === null || value === undefined) {
54
+ return null;
55
+ }
56
+ const cache = this.#cachedCookies.encryptedCookies;
57
+ if (cache[key] !== undefined) {
58
+ return cache[key];
59
+ }
60
+ const parsed = this.#client.decrypt(key, value);
61
+ if (parsed !== null) {
62
+ cache[key] = parsed;
63
+ }
64
+ return parsed;
65
+ }
66
+ list() {
67
+ return this.#cookies;
68
+ }
69
+ }
@@ -0,0 +1,11 @@
1
+ import type Encryption from '@adonisjs/encryption';
2
+ import type { CookieOptions } from '../types/response.js';
3
+ export declare class CookieSerializer {
4
+ #private;
5
+ constructor(encryption: Encryption);
6
+ encode(key: string, value: any, options?: Partial<CookieOptions & {
7
+ encode: boolean;
8
+ }>): string | null;
9
+ sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
10
+ encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
11
+ }
@@ -0,0 +1,39 @@
1
+ import cookie from 'cookie';
2
+ import string from '@poppinss/utils/string';
3
+ import { CookieClient } from './client.js';
4
+ export class CookieSerializer {
5
+ #client;
6
+ constructor(encryption) {
7
+ this.#client = new CookieClient(encryption);
8
+ }
9
+ #serializeAsCookie(key, value, options) {
10
+ let expires = options?.expires;
11
+ if (typeof expires === 'function') {
12
+ expires = expires();
13
+ }
14
+ let maxAge = options?.maxAge ? string.seconds.parse(options?.maxAge) : undefined;
15
+ const parsedOptions = Object.assign({}, options, { maxAge, expires });
16
+ return cookie.serialize(key, value, parsedOptions);
17
+ }
18
+ encode(key, value, options) {
19
+ const packedValue = options?.encode === false ? value : this.#client.encode(key, value);
20
+ if (packedValue === null || packedValue === undefined) {
21
+ return null;
22
+ }
23
+ return this.#serializeAsCookie(key, packedValue, options);
24
+ }
25
+ sign(key, value, options) {
26
+ const packedValue = this.#client.sign(key, value);
27
+ if (packedValue === null) {
28
+ return null;
29
+ }
30
+ return this.#serializeAsCookie(key, packedValue, options);
31
+ }
32
+ encrypt(key, value, options) {
33
+ const packedValue = this.#client.encrypt(key, value);
34
+ if (packedValue === null) {
35
+ return null;
36
+ }
37
+ return this.#serializeAsCookie(key, packedValue, options);
38
+ }
39
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ declare const _default: import("util").DebugLogger;
3
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { debuglog } from 'node:util';
2
+ export default debuglog('adonisjs:http');
@@ -0,0 +1,2 @@
1
+ import type { ServerConfig } from './types/server.js';
2
+ export declare function defineConfig(config: Partial<ServerConfig>): ServerConfig;
@@ -0,0 +1,40 @@
1
+ import proxyAddr from 'proxy-addr';
2
+ import string from '@poppinss/utils/string';
3
+ export function defineConfig(config) {
4
+ const normalizedConfig = {
5
+ allowMethodSpoofing: false,
6
+ trustProxy: proxyAddr.compile('loopback'),
7
+ subdomainOffset: 2,
8
+ generateRequestId: false,
9
+ useAsyncLocalStorage: false,
10
+ etag: false,
11
+ jsonpCallbackName: 'callback',
12
+ cookie: {
13
+ maxAge: '2h',
14
+ path: '/',
15
+ httpOnly: true,
16
+ secure: false,
17
+ sameSite: false,
18
+ },
19
+ qs: {
20
+ parse: {
21
+ depth: 5,
22
+ parameterLimit: 1000,
23
+ allowSparse: false,
24
+ arrayLimit: 20,
25
+ comma: true,
26
+ },
27
+ stringify: {
28
+ encode: true,
29
+ encodeValuesOnly: false,
30
+ arrayFormat: 'indices',
31
+ skipNulls: false,
32
+ },
33
+ },
34
+ ...config,
35
+ };
36
+ if (normalizedConfig.cookie.maxAge) {
37
+ normalizedConfig.cookie.maxAge = string.seconds.parse(normalizedConfig.cookie.maxAge);
38
+ }
39
+ return normalizedConfig;
40
+ }
@@ -0,0 +1,4 @@
1
+ import type { LazyImport } from './types/base.js';
2
+ import type { MiddlewareAsClass } from './types/middleware.js';
3
+ export declare function defineMiddleware(list: LazyImport<MiddlewareAsClass>[]): LazyImport<MiddlewareAsClass>[];
4
+ export declare function defineNamedMiddleware<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): NamedMiddleware;
@@ -0,0 +1,6 @@
1
+ export function defineMiddleware(list) {
2
+ return list;
3
+ }
4
+ export function defineNamedMiddleware(collection) {
5
+ return collection;
6
+ }
@@ -0,0 +1,5 @@
1
+ import { HttpException } from './http_exception.js';
2
+ import type { HttpContext } from '../http_context/main.js';
3
+ export declare class AbortException extends HttpException {
4
+ handle(error: HttpException, ctx: HttpContext): void;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { HttpException } from './http_exception.js';
2
+ export class AbortException extends HttpException {
3
+ handle(error, ctx) {
4
+ ctx.response.status(error.status).send(error.body);
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ import { Exception } from '@poppinss/utils';
2
+ export declare class CannotLookupRouteException extends Exception {
3
+ static status: number;
4
+ static code: string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Exception } from '@poppinss/utils';
2
+ export class CannotLookupRouteException extends Exception {
3
+ static status = 500;
4
+ static code = 'E_CANNOT_LOOKUP_ROUTE';
5
+ }
@@ -0,0 +1,6 @@
1
+ import { Exception } from '@poppinss/utils';
2
+ export declare class HttpException extends Exception {
3
+ body: any;
4
+ static code: string;
5
+ static invoke(body: any, status: number, code?: string): HttpException;
6
+ }
@@ -0,0 +1,20 @@
1
+ import { Exception } from '@poppinss/utils';
2
+ export class HttpException extends Exception {
3
+ body;
4
+ static code = 'E_HTTP_EXCEPTION';
5
+ static invoke(body, status, code = 'E_HTTP_EXCEPTION') {
6
+ if (body === null || body === undefined) {
7
+ const error = new this('HTTP Exception', { status, code });
8
+ error.body = 'Internal server error';
9
+ return error;
10
+ }
11
+ if (typeof body === 'object') {
12
+ const error = new this(body.message || 'HTTP Exception', { status, code });
13
+ error.body = body;
14
+ return error;
15
+ }
16
+ const error = new this(body, { status, code });
17
+ error.body = body;
18
+ return error;
19
+ }
20
+ }
@@ -0,0 +1,5 @@
1
+ import { HttpException } from './http_exception.js';
2
+ export declare class RouteNotFoundException extends HttpException {
3
+ static status: number;
4
+ static code: string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { HttpException } from './http_exception.js';
2
+ export class RouteNotFoundException extends HttpException {
3
+ static status = 404;
4
+ static code = 'E_ROUTE_NOT_FOUND';
5
+ }
@@ -1,69 +1,8 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../adonis-typings/index.d.ts" />
10
- /// <reference types="node" />
11
- import { Stats } from 'fs';
12
- import { Route } from './Router/Route';
13
- import { RouteGroup } from './Router/Group';
14
- import { BriskRoute } from './Router/BriskRoute';
15
- import { RouteResource } from './Router/Resource';
16
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
17
- import { RouteJSON, MakeUrlOptions, MakeSignedUrlOptions } from '@ioc:Adonis/Core/Route';
18
- /**
19
- * Makes input string consistent by having only the starting
20
- * slash
21
- */
1
+ import { Route } from './router/route.js';
2
+ import { BriskRoute } from './router/brisk.js';
3
+ import { RouteGroup } from './router/group.js';
4
+ import type { RouteJSON } from './types/route.js';
5
+ import { RouteResource } from './router/resource.js';
22
6
  export declare function dropSlash(input: string): string;
23
- /**
24
- * Converts and array of routes or route groups or route resource to a flat
25
- * list of route defination.
26
- */
27
- export declare function toRoutesJSON(routes: (RouteGroup | RouteResource | Route | BriskRoute)[]): RouteJSON[];
28
- /**
29
- * Makes url for a route pattern and params and querystring.
30
- */
31
- export declare function processPattern(pattern: string, data: any): string;
32
- /**
33
- * Returns a boolean telling if the return value must be used as
34
- * the response body or not
35
- */
36
- export declare function useReturnValue(returnValue: any, ctx: HttpContextContract): boolean;
37
- /**
38
- * Since finding the trusted proxy based upon the remote address
39
- * is an expensive function, we cache its result
40
- */
7
+ export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
41
8
  export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
42
- /**
43
- * Normalizes the makeURL options to work with the new API and the old
44
- * one as well
45
- */
46
- export declare function normalizeMakeUrlOptions(params?: any[] | MakeUrlOptions, options?: MakeUrlOptions): {
47
- params: any;
48
- qs: any;
49
- domain: string | undefined;
50
- prefixUrl: string | undefined;
51
- disableRouteLookup: boolean;
52
- };
53
- /**
54
- * Normalizes the make signed url options by allowing params to appear on
55
- * top level object with option to nest inside `params` property.
56
- */
57
- export declare function normalizeMakeSignedUrlOptions(params?: any[] | MakeSignedUrlOptions, options?: MakeSignedUrlOptions): {
58
- params: any;
59
- qs: any;
60
- domain: string | undefined;
61
- prefixUrl: string | undefined;
62
- expiresIn: any;
63
- purpose: any;
64
- disableRouteLookup: boolean;
65
- };
66
- /**
67
- * Wraps `fs.stat` to promise interface.
68
- */
69
- export declare function statFn(filePath: string): Promise<Stats>;