@adonisjs/http-server 6.8.2-6 → 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.
Files changed (208) hide show
  1. package/README.md +3 -6
  2. package/build/factories/http_context.d.ts +10 -1
  3. package/build/factories/http_context.js +27 -0
  4. package/build/factories/http_server.d.ts +8 -0
  5. package/build/factories/http_server.js +26 -0
  6. package/build/factories/main.d.ts +0 -1
  7. package/build/factories/main.js +8 -0
  8. package/build/factories/qs_parser_factory.d.ts +10 -1
  9. package/build/factories/qs_parser_factory.js +18 -0
  10. package/build/factories/request.d.ts +10 -1
  11. package/build/factories/request.js +31 -0
  12. package/build/factories/response.d.ts +10 -1
  13. package/build/factories/response.js +34 -0
  14. package/build/factories/router.d.ts +10 -1
  15. package/build/factories/router.js +25 -0
  16. package/build/factories/server_factory.d.ts +10 -1
  17. package/build/factories/server_factory.js +34 -0
  18. package/build/index.d.ts +0 -1
  19. package/build/index.js +8 -0
  20. package/build/src/cookies/client.d.ts +25 -1
  21. package/build/src/cookies/client.js +42 -0
  22. package/build/src/cookies/drivers/encrypted.d.ts +12 -1
  23. package/build/src/cookies/drivers/encrypted.js +20 -0
  24. package/build/src/cookies/drivers/plain.d.ts +12 -1
  25. package/build/src/cookies/drivers/plain.js +20 -0
  26. package/build/src/cookies/drivers/signed.d.ts +12 -1
  27. package/build/src/cookies/drivers/signed.js +20 -0
  28. package/build/src/cookies/parser.d.ts +28 -1
  29. package/build/src/cookies/parser.js +98 -0
  30. package/build/src/cookies/serializer.d.ts +22 -1
  31. package/build/src/cookies/serializer.js +40 -0
  32. package/build/src/debug.d.ts +0 -1
  33. package/build/src/debug.js +8 -0
  34. package/build/src/define_config.d.ts +3 -1
  35. package/build/src/define_config.js +11 -0
  36. package/build/src/define_middleware.d.ts +5 -1
  37. package/build/src/define_middleware.js +18 -0
  38. package/build/src/exception_handler.d.ts +65 -1
  39. package/build/src/exception_handler.js +95 -0
  40. package/build/src/exceptions.d.ts +6 -1
  41. package/build/src/exceptions.js +11 -0
  42. package/build/src/helpers.d.ts +14 -1
  43. package/build/src/helpers.js +22 -0
  44. package/build/src/http_context/local_storage.d.ts +3 -1
  45. package/build/src/http_context/local_storage.js +25 -0
  46. package/build/src/http_context/main.d.ts +36 -1
  47. package/build/src/http_context/main.js +54 -0
  48. package/build/src/qs.d.ts +4 -1
  49. package/build/src/qs.js +12 -0
  50. package/build/src/redirect.d.ts +24 -1
  51. package/build/src/redirect.js +60 -0
  52. package/build/src/request.d.ts +466 -1
  53. package/build/src/request.js +542 -0
  54. package/build/src/response.d.ts +425 -2
  55. package/build/src/response.js +608 -7
  56. package/build/src/router/brisk.d.ts +22 -1
  57. package/build/src/router/brisk.js +42 -0
  58. package/build/src/router/executor.d.ts +4 -1
  59. package/build/src/router/executor.js +12 -0
  60. package/build/src/router/factories/use_return_value.d.ts +4 -1
  61. package/build/src/router/factories/use_return_value.js +16 -3
  62. package/build/src/router/group.d.ts +47 -1
  63. package/build/src/router/group.js +88 -0
  64. package/build/src/router/lookup_store/main.d.ts +32 -1
  65. package/build/src/router/lookup_store/main.js +49 -0
  66. package/build/src/router/lookup_store/route_finder.d.ts +13 -1
  67. package/build/src/router/lookup_store/route_finder.js +21 -0
  68. package/build/src/router/lookup_store/url_builder.d.ts +36 -1
  69. package/build/src/router/lookup_store/url_builder.js +97 -0
  70. package/build/src/router/main.d.ts +87 -1
  71. package/build/src/router/main.js +142 -0
  72. package/build/src/router/matchers.d.ts +13 -1
  73. package/build/src/router/matchers.js +21 -0
  74. package/build/src/router/parser.d.ts +3 -1
  75. package/build/src/router/parser.js +12 -0
  76. package/build/src/router/resource.d.ts +28 -1
  77. package/build/src/router/resource.js +90 -0
  78. package/build/src/router/route.d.ts +65 -1
  79. package/build/src/router/route.js +142 -0
  80. package/build/src/router/store.d.ts +54 -1
  81. package/build/src/router/store.js +102 -0
  82. package/build/src/server/factories/final_handler.d.ts +5 -1
  83. package/build/src/server/factories/final_handler.js +13 -0
  84. package/build/src/server/factories/middleware_handler.d.ts +3 -1
  85. package/build/src/server/factories/middleware_handler.js +11 -0
  86. package/build/src/server/factories/write_response.d.ts +4 -1
  87. package/build/src/server/factories/write_response.js +12 -0
  88. package/build/src/server/main.d.ts +48 -1
  89. package/build/src/server/main.js +128 -0
  90. package/build/src/types/base.d.ts +12 -1
  91. package/build/src/types/base.js +8 -0
  92. package/build/src/types/main.d.ts +0 -1
  93. package/build/src/types/main.js +8 -0
  94. package/build/src/types/middleware.d.ts +18 -1
  95. package/build/src/types/middleware.js +8 -0
  96. package/build/src/types/qs.d.ts +53 -1
  97. package/build/src/types/qs.js +8 -0
  98. package/build/src/types/request.d.ts +32 -1
  99. package/build/src/types/request.js +8 -0
  100. package/build/src/types/response.d.ts +27 -1
  101. package/build/src/types/response.js +8 -0
  102. package/build/src/types/route.d.ts +87 -1
  103. package/build/src/types/route.js +8 -0
  104. package/build/src/types/server.d.ts +35 -1
  105. package/build/src/types/server.js +8 -0
  106. package/package.json +43 -70
  107. package/build/factories/http_context.d.ts.map +0 -1
  108. package/build/factories/main.d.ts.map +0 -1
  109. package/build/factories/qs_parser_factory.d.ts.map +0 -1
  110. package/build/factories/request.d.ts.map +0 -1
  111. package/build/factories/response.d.ts.map +0 -1
  112. package/build/factories/router.d.ts.map +0 -1
  113. package/build/factories/server_factory.d.ts.map +0 -1
  114. package/build/index.d.ts.map +0 -1
  115. package/build/src/cookies/client.d.ts.map +0 -1
  116. package/build/src/cookies/drivers/encrypted.d.ts.map +0 -1
  117. package/build/src/cookies/drivers/plain.d.ts.map +0 -1
  118. package/build/src/cookies/drivers/signed.d.ts.map +0 -1
  119. package/build/src/cookies/parser.d.ts.map +0 -1
  120. package/build/src/cookies/serializer.d.ts.map +0 -1
  121. package/build/src/debug.d.ts.map +0 -1
  122. package/build/src/define_config.d.ts.map +0 -1
  123. package/build/src/define_middleware.d.ts.map +0 -1
  124. package/build/src/exception_handler.d.ts.map +0 -1
  125. package/build/src/exceptions.d.ts.map +0 -1
  126. package/build/src/helpers.d.ts.map +0 -1
  127. package/build/src/http_context/local_storage.d.ts.map +0 -1
  128. package/build/src/http_context/main.d.ts.map +0 -1
  129. package/build/src/qs.d.ts.map +0 -1
  130. package/build/src/redirect.d.ts.map +0 -1
  131. package/build/src/request.d.ts.map +0 -1
  132. package/build/src/response.d.ts.map +0 -1
  133. package/build/src/router/brisk.d.ts.map +0 -1
  134. package/build/src/router/executor.d.ts.map +0 -1
  135. package/build/src/router/factories/use_return_value.d.ts.map +0 -1
  136. package/build/src/router/group.d.ts.map +0 -1
  137. package/build/src/router/lookup_store/main.d.ts.map +0 -1
  138. package/build/src/router/lookup_store/route_finder.d.ts.map +0 -1
  139. package/build/src/router/lookup_store/url_builder.d.ts.map +0 -1
  140. package/build/src/router/main.d.ts.map +0 -1
  141. package/build/src/router/matchers.d.ts.map +0 -1
  142. package/build/src/router/parser.d.ts.map +0 -1
  143. package/build/src/router/resource.d.ts.map +0 -1
  144. package/build/src/router/route.d.ts.map +0 -1
  145. package/build/src/router/store.d.ts.map +0 -1
  146. package/build/src/server/factories/final_handler.d.ts.map +0 -1
  147. package/build/src/server/factories/middleware_handler.d.ts.map +0 -1
  148. package/build/src/server/factories/write_response.d.ts.map +0 -1
  149. package/build/src/server/main.d.ts.map +0 -1
  150. package/build/src/types/base.d.ts.map +0 -1
  151. package/build/src/types/main.d.ts.map +0 -1
  152. package/build/src/types/middleware.d.ts.map +0 -1
  153. package/build/src/types/qs.d.ts.map +0 -1
  154. package/build/src/types/request.d.ts.map +0 -1
  155. package/build/src/types/response.d.ts.map +0 -1
  156. package/build/src/types/route.d.ts.map +0 -1
  157. package/build/src/types/server.d.ts.map +0 -1
  158. package/factories/http_context.ts +0 -73
  159. package/factories/main.ts +0 -15
  160. package/factories/qs_parser_factory.ts +0 -54
  161. package/factories/request.ts +0 -101
  162. package/factories/response.ts +0 -106
  163. package/factories/router.ts +0 -61
  164. package/factories/server_factory.ts +0 -94
  165. package/index.ts +0 -23
  166. package/src/cookies/client.ts +0 -98
  167. package/src/cookies/drivers/encrypted.ts +0 -42
  168. package/src/cookies/drivers/plain.ts +0 -37
  169. package/src/cookies/drivers/signed.ts +0 -42
  170. package/src/cookies/parser.ts +0 -196
  171. package/src/cookies/serializer.ts +0 -98
  172. package/src/debug.ts +0 -11
  173. package/src/define_config.ts +0 -56
  174. package/src/define_middleware.ts +0 -61
  175. package/src/exception_handler.ts +0 -290
  176. package/src/exceptions.ts +0 -55
  177. package/src/helpers.ts +0 -108
  178. package/src/http_context/local_storage.ts +0 -50
  179. package/src/http_context/main.ts +0 -126
  180. package/src/qs.ts +0 -31
  181. package/src/redirect.ts +0 -181
  182. package/src/request.ts +0 -982
  183. package/src/response.ts +0 -1421
  184. package/src/router/brisk.ts +0 -113
  185. package/src/router/executor.ts +0 -36
  186. package/src/router/factories/use_return_value.ts +0 -26
  187. package/src/router/group.ts +0 -243
  188. package/src/router/lookup_store/main.ts +0 -102
  189. package/src/router/lookup_store/route_finder.ts +0 -60
  190. package/src/router/lookup_store/url_builder.ts +0 -250
  191. package/src/router/main.ts +0 -431
  192. package/src/router/matchers.ts +0 -40
  193. package/src/router/parser.ts +0 -20
  194. package/src/router/resource.ts +0 -277
  195. package/src/router/route.ts +0 -363
  196. package/src/router/store.ts +0 -239
  197. package/src/server/factories/final_handler.ts +0 -38
  198. package/src/server/factories/middleware_handler.ts +0 -23
  199. package/src/server/factories/write_response.ts +0 -26
  200. package/src/server/main.ts +0 -356
  201. package/src/types/base.ts +0 -30
  202. package/src/types/main.ts +0 -16
  203. package/src/types/middleware.ts +0 -59
  204. package/src/types/qs.ts +0 -85
  205. package/src/types/request.ts +0 -52
  206. package/src/types/response.ts +0 -57
  207. package/src/types/route.ts +0 -217
  208. package/src/types/server.ts +0 -92
@@ -1,9 +1,29 @@
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 { parse } from 'node:url';
2
10
  import encodeUrl from 'encodeurl';
3
11
  import debug from './debug.js';
12
+ /**
13
+ * Exposes the API to construct redirect routes
14
+ */
4
15
  export class Redirect {
16
+ /**
17
+ * A boolean to forward the existing query string
18
+ */
5
19
  #forwardQueryString = false;
20
+ /**
21
+ * The status code for the redirect
22
+ */
6
23
  #statusCode = 302;
24
+ /**
25
+ * A custom query string to forward
26
+ */
7
27
  #queryString = {};
8
28
  #request;
9
29
  #response;
@@ -15,6 +35,9 @@ export class Redirect {
15
35
  this.#router = router;
16
36
  this.#qs = qs;
17
37
  }
38
+ /**
39
+ * Sends response by setting require headers
40
+ */
18
41
  #sendResponse(url, query) {
19
42
  const stringified = this.#qs.stringify(query);
20
43
  url = stringified ? `${url}?${stringified}` : url;
@@ -24,14 +47,24 @@ export class Redirect {
24
47
  this.#response.type('text/plain; charset=utf-8');
25
48
  this.#response.send(`Redirecting to ${url}`);
26
49
  }
50
+ /**
51
+ * Returns the referrer url
52
+ */
27
53
  #getReferrerUrl() {
28
54
  let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
29
55
  return Array.isArray(url) ? url[0] : url;
30
56
  }
57
+ /**
58
+ * Set a custom status code.
59
+ */
31
60
  status(statusCode) {
32
61
  this.#statusCode = statusCode;
33
62
  return this;
34
63
  }
64
+ /**
65
+ * Clearing query string values added using the
66
+ * "withQs" method
67
+ */
35
68
  clearQs() {
36
69
  this.#forwardQueryString = false;
37
70
  this.#queryString = {};
@@ -49,18 +82,33 @@ export class Redirect {
49
82
  Object.assign(this.#queryString, name);
50
83
  return this;
51
84
  }
85
+ /**
86
+ * Redirect to the previous path.
87
+ */
52
88
  back() {
53
89
  let query = {};
54
90
  const referrerUrl = this.#getReferrerUrl();
55
91
  const url = parse(referrerUrl);
56
92
  debug('referrer url "%s"', referrerUrl);
57
93
  debug('referrer base url "%s"', url.pathname);
94
+ /**
95
+ * Parse query string from the referrer url
96
+ */
58
97
  if (this.#forwardQueryString) {
59
98
  query = this.#qs.parse(url.query || '');
60
99
  }
100
+ /**
101
+ * Append custom query string
102
+ */
61
103
  Object.assign(query, this.#queryString);
104
+ /**
105
+ * Redirect
106
+ */
62
107
  this.#sendResponse(url.pathname || '', query);
63
108
  }
109
+ /**
110
+ * Redirect the request using a route identifier.
111
+ */
64
112
  toRoute(routeIdentifier, params, options) {
65
113
  if (options && options.qs) {
66
114
  this.withQs(options.qs);
@@ -69,12 +117,24 @@ export class Redirect {
69
117
  const url = this.#router.makeUrl(routeIdentifier, params, options);
70
118
  return this.toPath(url);
71
119
  }
120
+ /**
121
+ * Redirect the request using a path.
122
+ */
72
123
  toPath(url) {
73
124
  let query = {};
125
+ /**
126
+ * Extract query string from the current URL
127
+ */
74
128
  if (this.#forwardQueryString) {
75
129
  query = this.#qs.parse(parse(this.#request.url).query || '');
76
130
  }
131
+ /**
132
+ * Assign custom query string
133
+ */
77
134
  Object.assign(query, this.#queryString);
135
+ /**
136
+ * Redirect
137
+ */
78
138
  this.#sendResponse(url, query);
79
139
  }
80
140
  }
@@ -7,67 +7,530 @@ import { ServerResponse, IncomingMessage, IncomingHttpHeaders } from 'node:http'
7
7
  import type { Qs } from './qs.js';
8
8
  import { RequestConfig } from './types/request.js';
9
9
  import type { HttpContext } from './http_context/main.js';
10
+ /**
11
+ * HTTP Request class exposes the interface to consistently read values
12
+ * related to a given HTTP request. The class is wrapper over
13
+ * [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
14
+ * and has extended API.
15
+ *
16
+ * You can access the original [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
17
+ * using `request.request` property.
18
+ */
10
19
  export declare class Request extends Macroable {
11
20
  #private;
12
21
  request: IncomingMessage;
13
22
  response: ServerResponse;
23
+ /**
24
+ * Parses copy of the URL with query string as a string and not
25
+ * object. This is done to build URL's with query string without
26
+ * stringifying the object
27
+ */
14
28
  parsedUrl: UrlWithStringQuery;
29
+ /**
30
+ * The ctx will be set by the context itself. It creates a circular
31
+ * reference
32
+ */
15
33
  ctx?: HttpContext;
16
34
  constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: RequestConfig, qsParser: Qs);
35
+ /**
36
+ * Returns the request id from the `x-request-id` header. The
37
+ * header is untouched, if it already exists.
38
+ */
17
39
  id(): string | undefined;
40
+ /**
41
+ * Set initial request body. A copy of the input will be maintained as the original
42
+ * request body. Since the request body and query string is subject to mutations, we
43
+ * keep one original reference to flash old data (whenever required).
44
+ *
45
+ * This method is supposed to be invoked by the body parser and must be called only
46
+ * once. For further mutations make use of `updateBody` method.
47
+ */
18
48
  setInitialBody(body: Record<string, any>): void;
49
+ /**
50
+ * Update the request body with new data object. The `all` property
51
+ * will be re-computed by merging the query string and request
52
+ * body.
53
+ */
19
54
  updateBody(body: Record<string, any>): void;
55
+ /**
56
+ * Update the request raw body. Bodyparser sets this when unable to parse
57
+ * the request body or when request is multipart/form-data.
58
+ */
20
59
  updateRawBody(rawBody: string): void;
60
+ /**
61
+ * Update the query string with the new data object. The `all` property
62
+ * will be re-computed by merging the query and the request body.
63
+ */
21
64
  updateQs(data: Record<string, any>): void;
65
+ /**
66
+ * Returns route params
67
+ */
22
68
  params(): Record<string, any>;
69
+ /**
70
+ * Returns the query string object by reference
71
+ */
23
72
  qs(): Record<string, any>;
73
+ /**
74
+ * Returns reference to the request body
75
+ */
24
76
  body(): Record<string, any>;
77
+ /**
78
+ * Returns reference to the merged copy of request body
79
+ * and query string
80
+ */
25
81
  all(): Record<string, any>;
82
+ /**
83
+ * Returns reference to the merged copy of original request
84
+ * query string and body
85
+ */
26
86
  original(): Record<string, any>;
87
+ /**
88
+ * Returns the request raw body (if exists), or returns `null`.
89
+ *
90
+ * Ideally you must be dealing with the parsed body accessed using [[input]], [[all]] or
91
+ * [[post]] methods. The `raw` body is always a string.
92
+ */
27
93
  raw(): string | null;
94
+ /**
95
+ * Returns value for a given key from the request body or query string.
96
+ * The `defaultValue` is used when original value is `undefined`.
97
+ *
98
+ * @example
99
+ * ```js
100
+ * request.input('username')
101
+ *
102
+ * // with default value
103
+ * request.input('username', 'virk')
104
+ * ```
105
+ */
28
106
  input(key: string, defaultValue?: any): any;
107
+ /**
108
+ * Returns value for a given key from route params
109
+ *
110
+ * @example
111
+ * ```js
112
+ * request.param('id')
113
+ *
114
+ * // with default value
115
+ * request.param('id', 1)
116
+ * ```
117
+ */
29
118
  param(key: string, defaultValue?: any): any;
119
+ /**
120
+ * Get everything from the request body except the given keys.
121
+ *
122
+ * @example
123
+ * ```js
124
+ * request.except(['_csrf'])
125
+ * ```
126
+ */
30
127
  except(keys: string[]): Record<string, any>;
128
+ /**
129
+ * Get value for specified keys.
130
+ *
131
+ * @example
132
+ * ```js
133
+ * request.only(['username', 'age'])
134
+ * ```
135
+ */
31
136
  only<T extends string>(keys: T[]): {
32
137
  [K in T]: any;
33
138
  };
139
+ /**
140
+ * Returns the HTTP request method. This is the original
141
+ * request method. For spoofed request method, make
142
+ * use of [[method]].
143
+ *
144
+ * @example
145
+ * ```js
146
+ * request.intended()
147
+ * ```
148
+ */
34
149
  intended(): string;
150
+ /**
151
+ * Returns the request HTTP method by taking method spoofing into account.
152
+ *
153
+ * Method spoofing works when all of the following are true.
154
+ *
155
+ * 1. `app.http.allowMethodSpoofing` config value is true.
156
+ * 2. request query string has `_method`.
157
+ * 3. The [[intended]] request method is `POST`.
158
+ *
159
+ * @example
160
+ * ```js
161
+ * request.method()
162
+ * ```
163
+ */
35
164
  method(): string;
165
+ /**
166
+ * Returns a copy of headers as an object
167
+ */
36
168
  headers(): IncomingHttpHeaders;
169
+ /**
170
+ * Returns value for a given header key. The default value is
171
+ * used when original value is `undefined`.
172
+ */
37
173
  header(key: string, defaultValue?: any): string | undefined;
174
+ /**
175
+ * Returns the ip address of the user. This method is optimize to fetch
176
+ * ip address even when running your AdonisJs app behind a proxy.
177
+ *
178
+ * You can also define your own custom function to compute the ip address by
179
+ * defining `app.http.getIp` as a function inside the config file.
180
+ *
181
+ * ```js
182
+ * {
183
+ * http: {
184
+ * getIp (request) {
185
+ * // I am using nginx as a proxy server and want to trust 'x-real-ip'
186
+ * return request.header('x-real-ip')
187
+ * }
188
+ * }
189
+ * }
190
+ * ```
191
+ *
192
+ * You can control the behavior of trusting the proxy values by defining it
193
+ * inside the `config/app.js` file.
194
+ *
195
+ * ```js
196
+ * {
197
+ * http: {
198
+ * trustProxy: '127.0.0.1'
199
+ * }
200
+ * }
201
+ * ```
202
+ *
203
+ * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
204
+ */
38
205
  ip(): string;
206
+ /**
207
+ * Returns an array of ip addresses from most to least trusted one.
208
+ * This method is optimize to fetch ip address even when running
209
+ * your AdonisJs app behind a proxy.
210
+ *
211
+ * You can control the behavior of trusting the proxy values by defining it
212
+ * inside the `config/app.js` file.
213
+ *
214
+ * ```js
215
+ * {
216
+ * http: {
217
+ * trustProxy: '127.0.0.1'
218
+ * }
219
+ * }
220
+ * ```
221
+ *
222
+ * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
223
+ */
39
224
  ips(): string[];
225
+ /**
226
+ * Returns the request protocol by checking for the URL protocol or
227
+ * `X-Forwarded-Proto` header.
228
+ *
229
+ * If the `trust` is evaluated to `false`, then URL protocol is returned,
230
+ * otherwise `X-Forwarded-Proto` header is used (if exists).
231
+ *
232
+ * You can control the behavior of trusting the proxy values by defining it
233
+ * inside the `config/app.js` file.
234
+ *
235
+ * ```js
236
+ * {
237
+ * http: {
238
+ * trustProxy: '127.0.0.1'
239
+ * }
240
+ * }
241
+ * ```
242
+ *
243
+ * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
244
+ */
40
245
  protocol(): string;
246
+ /**
247
+ * Returns a boolean telling if request is served over `https`
248
+ * or not. Check [[protocol]] method to know how protocol is
249
+ * fetched.
250
+ */
41
251
  secure(): boolean;
252
+ /**
253
+ * Returns the request host. If proxy headers are trusted, then
254
+ * `X-Forwarded-Host` is given priority over the `Host` header.
255
+ *
256
+ * You can control the behavior of trusting the proxy values by defining it
257
+ * inside the `config/app.js` file.
258
+ *
259
+ * ```js
260
+ * {
261
+ * http: {
262
+ * trustProxy: '127.0.0.1'
263
+ * }
264
+ * }
265
+ * ```
266
+ *
267
+ * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
268
+ */
42
269
  host(): string | null;
270
+ /**
271
+ * Returns the request hostname. If proxy headers are trusted, then
272
+ * `X-Forwarded-Host` is given priority over the `Host` header.
273
+ *
274
+ * You can control the behavior of trusting the proxy values by defining it
275
+ * inside the `config/app.js` file.
276
+ *
277
+ * ```js
278
+ * {
279
+ * http: {
280
+ * trustProxy: '127.0.0.1'
281
+ * }
282
+ * }
283
+ * ```
284
+ *
285
+ * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
286
+ */
43
287
  hostname(): string | null;
288
+ /**
289
+ * Returns an array of subdomains for the given host. An empty array is
290
+ * returned if [[hostname]] is `null` or is an IP address.
291
+ *
292
+ * Also `www` is not considered as a subdomain
293
+ */
44
294
  subdomains(): string[];
295
+ /**
296
+ * Returns a boolean telling, if request `X-Requested-With === 'xmlhttprequest'`
297
+ * or not.
298
+ */
45
299
  ajax(): boolean;
300
+ /**
301
+ * Returns a boolean telling, if request has `X-Pjax` header
302
+ * set or not
303
+ */
46
304
  pjax(): boolean;
305
+ /**
306
+ * Returns the request relative URL.
307
+ *
308
+ * @example
309
+ * ```js
310
+ * request.url()
311
+ *
312
+ * // include query string
313
+ * request.url(true)
314
+ * ```
315
+ */
47
316
  url(includeQueryString?: boolean): string;
317
+ /**
318
+ * Returns the complete HTTP url by combining
319
+ * [[protocol]]://[[hostname]]/[[url]]
320
+ *
321
+ * @example
322
+ * ```js
323
+ * request.completeUrl()
324
+ *
325
+ * // include query string
326
+ * request.completeUrl(true)
327
+ * ```
328
+ */
48
329
  completeUrl(includeQueryString?: boolean): string;
330
+ /**
331
+ * Find if the current HTTP request is for the given route or the routes
332
+ */
49
333
  matchesRoute(routeIdentifier: string | string[]): boolean;
334
+ /**
335
+ * Returns the best matching content type of the request by
336
+ * matching against the given types.
337
+ *
338
+ * The content type is picked from the `content-type` header and request
339
+ * must have body.
340
+ *
341
+ * The method response highly depends upon the types array values. Described below:
342
+ *
343
+ * | Type(s) | Return value |
344
+ * |----------|---------------|
345
+ * | ['json'] | json |
346
+ * | ['application/*'] | application/json |
347
+ * | ['vnd+json'] | application/json |
348
+ *
349
+ * @example
350
+ * ```js
351
+ * const bodyType = request.is(['json', 'xml'])
352
+ *
353
+ * if (bodyType === 'json') {
354
+ * // process JSON
355
+ * }
356
+ *
357
+ * if (bodyType === 'xml') {
358
+ * // process XML
359
+ * }
360
+ * ```
361
+ */
50
362
  is(types: string[]): string | null;
363
+ /**
364
+ * Returns the best type using `Accept` header and
365
+ * by matching it against the given types.
366
+ *
367
+ * If nothing is matched, then `null` will be returned
368
+ *
369
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
370
+ * docs too.
371
+ *
372
+ * @example
373
+ * ```js
374
+ * switch (request.accepts(['json', 'html'])) {
375
+ * case 'json':
376
+ * return response.json(user)
377
+ * case 'html':
378
+ * return view.render('user', { user })
379
+ * default:
380
+ * // decide yourself
381
+ * }
382
+ * ```
383
+ */
51
384
  accepts<T extends string>(types: T[]): T | null;
385
+ /**
386
+ * Return the types that the request accepts, in the order of the
387
+ * client's preference (most preferred first).
388
+ *
389
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
390
+ * docs too.
391
+ */
52
392
  types(): string[];
393
+ /**
394
+ * Returns the best language using `Accept-language` header
395
+ * and by matching it against the given languages.
396
+ *
397
+ * If nothing is matched, then `null` will be returned
398
+ *
399
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
400
+ * docs too.
401
+ *
402
+ * @example
403
+ * ```js
404
+ * switch (request.language(['fr', 'de'])) {
405
+ * case 'fr':
406
+ * return view.render('about', { lang: 'fr' })
407
+ * case 'de':
408
+ * return view.render('about', { lang: 'de' })
409
+ * default:
410
+ * return view.render('about', { lang: 'en' })
411
+ * }
412
+ * ```
413
+ */
53
414
  language<T extends string>(languages: T[]): T | null;
415
+ /**
416
+ * Return the languages that the request accepts, in the order of the
417
+ * client's preference (most preferred first).
418
+ *
419
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
420
+ * docs too.
421
+ */
54
422
  languages(): string[];
423
+ /**
424
+ * Returns the best charset using `Accept-charset` header
425
+ * and by matching it against the given charsets.
426
+ *
427
+ * If nothing is matched, then `null` will be returned
428
+ *
429
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
430
+ * docs too.
431
+ *
432
+ * @example
433
+ * ```js
434
+ * switch (request.charset(['utf-8', 'ISO-8859-1'])) {
435
+ * case 'utf-8':
436
+ * // make utf-8 friendly response
437
+ * case 'ISO-8859-1':
438
+ * // make ISO-8859-1 friendly response
439
+ * }
440
+ * ```
441
+ */
55
442
  charset<T extends string>(charsets: T[]): T | null;
443
+ /**
444
+ * Return the charsets that the request accepts, in the order of the
445
+ * client's preference (most preferred first).
446
+ *
447
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
448
+ * docs too.
449
+ */
56
450
  charsets(): string[];
451
+ /**
452
+ * Returns the best encoding using `Accept-encoding` header
453
+ * and by matching it against the given encodings.
454
+ *
455
+ * If nothing is matched, then `null` will be returned
456
+ *
457
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
458
+ * docs too.
459
+ */
57
460
  encoding<T extends string>(encodings: T[]): T | null;
461
+ /**
462
+ * Return the charsets that the request accepts, in the order of the
463
+ * client's preference (most preferred first).
464
+ *
465
+ * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
466
+ * docs too.
467
+ */
58
468
  encodings(): string[];
469
+ /**
470
+ * Returns a boolean telling if request has body
471
+ */
59
472
  hasBody(): boolean;
473
+ /**
474
+ * Returns a boolean telling if the new response etag evaluates same
475
+ * as the request header `if-none-match`. In case of `true`, the
476
+ * server must return `304` response, telling the browser to
477
+ * use the client cache.
478
+ *
479
+ * You won't have to deal with this method directly, since AdonisJs will
480
+ * handle this for you when `http.etag = true` inside `config/app.js` file.
481
+ *
482
+ * However, this is how you can use it manually.
483
+ *
484
+ * ```js
485
+ * const responseBody = view.render('some-view')
486
+ *
487
+ * // sets the HTTP etag header for response
488
+ * response.setEtag(responseBody)
489
+ *
490
+ * if (request.fresh()) {
491
+ * response.sendStatus(304)
492
+ * } else {
493
+ * response.send(responseBody)
494
+ * }
495
+ * ```
496
+ */
60
497
  fresh(): boolean;
498
+ /**
499
+ * Opposite of [[fresh]]
500
+ */
61
501
  stale(): boolean;
502
+ /**
503
+ * Returns all parsed and signed cookies. Signed cookies ensures
504
+ * that their value isn't tampered.
505
+ */
62
506
  cookiesList(): Record<string, any>;
507
+ /**
508
+ * Returns value for a given key from signed cookies. Optional
509
+ * defaultValue is returned when actual value is undefined.
510
+ */
63
511
  cookie(key: string, defaultValue?: string): any;
512
+ /**
513
+ * Returns value for a given key from signed cookies. Optional
514
+ * defaultValue is returned when actual value is undefined.
515
+ */
64
516
  encryptedCookie(key: string, defaultValue?: string): any;
517
+ /**
518
+ * Returns value for a given key from unsigned cookies. Optional
519
+ * defaultValue is returned when actual value is undefined.
520
+ */
65
521
  plainCookie(key: string, options?: {
66
522
  defaultValue?: string;
67
523
  encoded?: boolean;
68
524
  }): any;
69
525
  plainCookie(key: string, defaultValue?: string, encoded?: boolean): any;
526
+ /**
527
+ * Returns a boolean telling if a signed url as a valid signature
528
+ * or not.
529
+ */
70
530
  hasValidSignature(purpose?: string): boolean;
531
+ /**
532
+ * Serializes request to JSON format
533
+ */
71
534
  serialize(): {
72
535
  id: string | undefined;
73
536
  url: string;
@@ -82,6 +545,9 @@ export declare class Request extends Macroable {
82
545
  ip: string;
83
546
  subdomains: Record<string, any>;
84
547
  };
548
+ /**
549
+ * toJSON copy of the request
550
+ */
85
551
  toJSON(): {
86
552
  id: string | undefined;
87
553
  url: string;
@@ -97,4 +563,3 @@ export declare class Request extends Macroable {
97
563
  subdomains: Record<string, any>;
98
564
  };
99
565
  }
100
- //# sourceMappingURL=request.d.ts.map