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