@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.
- 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 +98 -96
- 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 -438
- 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 -44
- 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 -412
- 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 -141
- 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
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import cuid from 'cuid';
|
|
2
|
+
import fresh from 'fresh';
|
|
3
|
+
import typeIs from 'type-is';
|
|
4
|
+
import accepts from 'accepts';
|
|
5
|
+
import { isIP } from 'node:net';
|
|
6
|
+
import proxyaddr from 'proxy-addr';
|
|
7
|
+
import { safeEqual } from '@poppinss/utils';
|
|
8
|
+
import lodash from '@poppinss/utils/lodash';
|
|
9
|
+
import { Macroable } from '@poppinss/macroable';
|
|
10
|
+
import { parse } from 'node:url';
|
|
11
|
+
import { trustProxy } from './helpers.js';
|
|
12
|
+
import { CookieParser } from './cookies/parser.js';
|
|
13
|
+
export class Request extends Macroable {
|
|
14
|
+
request;
|
|
15
|
+
response;
|
|
16
|
+
#qsParser;
|
|
17
|
+
#encryption;
|
|
18
|
+
#config;
|
|
19
|
+
#requestBody = {};
|
|
20
|
+
#requestData = {};
|
|
21
|
+
#originalRequestData = {};
|
|
22
|
+
#requestQs = {};
|
|
23
|
+
#rawRequestBody;
|
|
24
|
+
#lazyAccepts;
|
|
25
|
+
#cookieParser;
|
|
26
|
+
parsedUrl;
|
|
27
|
+
ctx;
|
|
28
|
+
constructor(request, response, encryption, config, qsParser) {
|
|
29
|
+
super();
|
|
30
|
+
this.request = request;
|
|
31
|
+
this.response = response;
|
|
32
|
+
this.#qsParser = qsParser;
|
|
33
|
+
this.#config = config;
|
|
34
|
+
this.#encryption = encryption;
|
|
35
|
+
this.parsedUrl = parse(this.request.url, false);
|
|
36
|
+
this.#parseQueryString();
|
|
37
|
+
}
|
|
38
|
+
#parseQueryString() {
|
|
39
|
+
if (this.parsedUrl.query) {
|
|
40
|
+
this.updateQs(this.#qsParser.parse(this.parsedUrl.query));
|
|
41
|
+
this.#originalRequestData = { ...this.#requestData };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
#initiateCookieParser() {
|
|
45
|
+
if (!this.#cookieParser) {
|
|
46
|
+
this.#cookieParser = new CookieParser(this.header('cookie'), this.#encryption);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
#initiateAccepts() {
|
|
50
|
+
this.#lazyAccepts = this.#lazyAccepts || accepts(this.request);
|
|
51
|
+
}
|
|
52
|
+
id() {
|
|
53
|
+
let requestId = this.header('x-request-id');
|
|
54
|
+
if (!requestId && this.#config.generateRequestId) {
|
|
55
|
+
requestId = cuid();
|
|
56
|
+
this.request.headers['x-request-id'] = requestId;
|
|
57
|
+
}
|
|
58
|
+
return requestId;
|
|
59
|
+
}
|
|
60
|
+
setInitialBody(body) {
|
|
61
|
+
if (this.#originalRequestData && Object.isFrozen(this.#originalRequestData)) {
|
|
62
|
+
throw new Error('Cannot re-set initial body. Use "request.updateBody" instead');
|
|
63
|
+
}
|
|
64
|
+
this.updateBody(body);
|
|
65
|
+
this.#originalRequestData = Object.freeze({ ...this.#requestData });
|
|
66
|
+
}
|
|
67
|
+
updateBody(body) {
|
|
68
|
+
this.#requestBody = body;
|
|
69
|
+
this.#requestData = { ...this.#requestBody, ...this.#requestQs };
|
|
70
|
+
}
|
|
71
|
+
updateRawBody(rawBody) {
|
|
72
|
+
this.#rawRequestBody = rawBody;
|
|
73
|
+
}
|
|
74
|
+
updateQs(data) {
|
|
75
|
+
this.#requestQs = data;
|
|
76
|
+
this.#requestData = { ...this.#requestBody, ...this.#requestQs };
|
|
77
|
+
}
|
|
78
|
+
params() {
|
|
79
|
+
return this.ctx?.params || {};
|
|
80
|
+
}
|
|
81
|
+
qs() {
|
|
82
|
+
return this.#requestQs;
|
|
83
|
+
}
|
|
84
|
+
body() {
|
|
85
|
+
return this.#requestBody;
|
|
86
|
+
}
|
|
87
|
+
all() {
|
|
88
|
+
return this.#requestData;
|
|
89
|
+
}
|
|
90
|
+
original() {
|
|
91
|
+
return this.#originalRequestData;
|
|
92
|
+
}
|
|
93
|
+
raw() {
|
|
94
|
+
return this.#rawRequestBody || null;
|
|
95
|
+
}
|
|
96
|
+
input(key, defaultValue) {
|
|
97
|
+
return lodash.get(this.#requestData, key, defaultValue);
|
|
98
|
+
}
|
|
99
|
+
param(key, defaultValue) {
|
|
100
|
+
return lodash.get(this.params(), key, defaultValue);
|
|
101
|
+
}
|
|
102
|
+
except(keys) {
|
|
103
|
+
return lodash.omit(this.#requestData, keys);
|
|
104
|
+
}
|
|
105
|
+
only(keys) {
|
|
106
|
+
return lodash.pick(this.#requestData, keys);
|
|
107
|
+
}
|
|
108
|
+
intended() {
|
|
109
|
+
return this.request.method;
|
|
110
|
+
}
|
|
111
|
+
method() {
|
|
112
|
+
if (this.#config.allowMethodSpoofing && this.intended() === 'POST') {
|
|
113
|
+
return this.input('_method', this.intended()).toUpperCase();
|
|
114
|
+
}
|
|
115
|
+
return this.intended();
|
|
116
|
+
}
|
|
117
|
+
headers() {
|
|
118
|
+
return this.request.headers;
|
|
119
|
+
}
|
|
120
|
+
header(key, defaultValue) {
|
|
121
|
+
key = key.toLowerCase();
|
|
122
|
+
const headers = this.headers();
|
|
123
|
+
switch (key) {
|
|
124
|
+
case 'referer':
|
|
125
|
+
case 'referrer':
|
|
126
|
+
return headers.referrer || headers.referer || defaultValue;
|
|
127
|
+
default:
|
|
128
|
+
return headers[key] || defaultValue;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
ip() {
|
|
132
|
+
const ipFn = this.#config.getIp;
|
|
133
|
+
if (typeof ipFn === 'function') {
|
|
134
|
+
return ipFn(this);
|
|
135
|
+
}
|
|
136
|
+
return proxyaddr(this.request, this.#config.trustProxy);
|
|
137
|
+
}
|
|
138
|
+
ips() {
|
|
139
|
+
return proxyaddr.all(this.request, this.#config.trustProxy);
|
|
140
|
+
}
|
|
141
|
+
protocol() {
|
|
142
|
+
if ('encrypted' in this.request.socket) {
|
|
143
|
+
return 'https';
|
|
144
|
+
}
|
|
145
|
+
if (!trustProxy(this.request.socket.remoteAddress, this.#config.trustProxy)) {
|
|
146
|
+
return this.parsedUrl.protocol || 'http';
|
|
147
|
+
}
|
|
148
|
+
const forwardedProtocol = this.header('X-Forwarded-Proto');
|
|
149
|
+
return forwardedProtocol ? forwardedProtocol.split(/\s*,\s*/)[0] : 'http';
|
|
150
|
+
}
|
|
151
|
+
secure() {
|
|
152
|
+
return this.protocol() === 'https';
|
|
153
|
+
}
|
|
154
|
+
host() {
|
|
155
|
+
let host = this.header('host');
|
|
156
|
+
if (trustProxy(this.request.socket.remoteAddress, this.#config.trustProxy)) {
|
|
157
|
+
host = this.header('X-Forwarded-Host') || host;
|
|
158
|
+
}
|
|
159
|
+
if (!host) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return host;
|
|
163
|
+
}
|
|
164
|
+
hostname() {
|
|
165
|
+
const host = this.host();
|
|
166
|
+
if (!host) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
|
|
170
|
+
const index = host.indexOf(':', offset);
|
|
171
|
+
return index !== -1 ? host.substring(0, index) : host;
|
|
172
|
+
}
|
|
173
|
+
subdomains() {
|
|
174
|
+
const hostname = this.hostname();
|
|
175
|
+
if (!hostname || isIP(hostname)) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const offset = this.#config.subdomainOffset;
|
|
179
|
+
const subdomains = hostname.split('.').reverse().slice(offset);
|
|
180
|
+
if (subdomains[subdomains.length - 1] === 'www') {
|
|
181
|
+
subdomains.splice(subdomains.length - 1, 1);
|
|
182
|
+
}
|
|
183
|
+
return subdomains;
|
|
184
|
+
}
|
|
185
|
+
ajax() {
|
|
186
|
+
const xRequestedWith = this.header('X-Requested-With', '');
|
|
187
|
+
return xRequestedWith.toLowerCase() === 'xmlhttprequest';
|
|
188
|
+
}
|
|
189
|
+
pjax() {
|
|
190
|
+
return !!this.header('X-Pjax');
|
|
191
|
+
}
|
|
192
|
+
url(includeQueryString) {
|
|
193
|
+
const pathname = this.parsedUrl.pathname;
|
|
194
|
+
return includeQueryString && this.parsedUrl.query
|
|
195
|
+
? `${pathname}?${this.parsedUrl.query}`
|
|
196
|
+
: pathname;
|
|
197
|
+
}
|
|
198
|
+
completeUrl(includeQueryString) {
|
|
199
|
+
const protocol = this.protocol();
|
|
200
|
+
const hostname = this.host();
|
|
201
|
+
return `${protocol}://${hostname}${this.url(includeQueryString)}`;
|
|
202
|
+
}
|
|
203
|
+
matchesRoute(routeIdentifier) {
|
|
204
|
+
if (!this.ctx || !this.ctx.route) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const route = this.ctx.route;
|
|
208
|
+
return !!(Array.isArray(routeIdentifier) ? routeIdentifier : [routeIdentifier]).find((identifier) => {
|
|
209
|
+
if (route.pattern === identifier || route.name === identifier) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
if (typeof route.handler === 'function') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return route.handler.name === identifier;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
is(types) {
|
|
219
|
+
return typeIs(this.request, types) || null;
|
|
220
|
+
}
|
|
221
|
+
accepts(types) {
|
|
222
|
+
this.#initiateAccepts();
|
|
223
|
+
return this.#lazyAccepts.type(types) || null;
|
|
224
|
+
}
|
|
225
|
+
types() {
|
|
226
|
+
this.#initiateAccepts();
|
|
227
|
+
return this.#lazyAccepts.types();
|
|
228
|
+
}
|
|
229
|
+
language(languages) {
|
|
230
|
+
this.#initiateAccepts();
|
|
231
|
+
return this.#lazyAccepts.language(languages) || null;
|
|
232
|
+
}
|
|
233
|
+
languages() {
|
|
234
|
+
this.#initiateAccepts();
|
|
235
|
+
return this.#lazyAccepts.languages();
|
|
236
|
+
}
|
|
237
|
+
charset(charsets) {
|
|
238
|
+
this.#initiateAccepts();
|
|
239
|
+
return this.#lazyAccepts.charset(charsets) || null;
|
|
240
|
+
}
|
|
241
|
+
charsets() {
|
|
242
|
+
this.#initiateAccepts();
|
|
243
|
+
return this.#lazyAccepts.charsets();
|
|
244
|
+
}
|
|
245
|
+
encoding(encodings) {
|
|
246
|
+
this.#initiateAccepts();
|
|
247
|
+
return this.#lazyAccepts.encoding(encodings) || null;
|
|
248
|
+
}
|
|
249
|
+
encodings() {
|
|
250
|
+
this.#initiateAccepts();
|
|
251
|
+
return this.#lazyAccepts.encodings();
|
|
252
|
+
}
|
|
253
|
+
hasBody() {
|
|
254
|
+
return typeIs.hasBody(this.request);
|
|
255
|
+
}
|
|
256
|
+
fresh() {
|
|
257
|
+
if (['GET', 'HEAD'].indexOf(this.intended()) === -1) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
const status = this.response.statusCode;
|
|
261
|
+
if ((status >= 200 && status < 300) || status === 304) {
|
|
262
|
+
return fresh(this.headers(), this.response.getHeaders());
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
stale() {
|
|
267
|
+
return !this.fresh();
|
|
268
|
+
}
|
|
269
|
+
cookiesList() {
|
|
270
|
+
this.#initiateCookieParser();
|
|
271
|
+
return this.#cookieParser.list();
|
|
272
|
+
}
|
|
273
|
+
cookie(key, defaultValue) {
|
|
274
|
+
this.#initiateCookieParser();
|
|
275
|
+
return this.#cookieParser.unsign(key) || defaultValue;
|
|
276
|
+
}
|
|
277
|
+
encryptedCookie(key, defaultValue) {
|
|
278
|
+
this.#initiateCookieParser();
|
|
279
|
+
return this.#cookieParser.decrypt(key) || defaultValue;
|
|
280
|
+
}
|
|
281
|
+
plainCookie(key, defaultValue, encoded) {
|
|
282
|
+
this.#initiateCookieParser();
|
|
283
|
+
return this.#cookieParser.decode(key, encoded) || defaultValue;
|
|
284
|
+
}
|
|
285
|
+
hasValidSignature(purpose) {
|
|
286
|
+
const { signature, ...rest } = this.qs();
|
|
287
|
+
if (!signature) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
const signedUrl = this.#encryption.verifier.unsign(signature, purpose);
|
|
291
|
+
if (!signedUrl) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
const queryString = this.#qsParser.stringify(rest);
|
|
295
|
+
return queryString
|
|
296
|
+
? safeEqual(signedUrl, `${this.url()}?${queryString}`)
|
|
297
|
+
: safeEqual(signedUrl, this.url());
|
|
298
|
+
}
|
|
299
|
+
toJSON() {
|
|
300
|
+
return {
|
|
301
|
+
id: this.id(),
|
|
302
|
+
url: this.url(),
|
|
303
|
+
query: this.parsedUrl.query,
|
|
304
|
+
body: this.all(),
|
|
305
|
+
params: this.params(),
|
|
306
|
+
headers: this.headers(),
|
|
307
|
+
method: this.method(),
|
|
308
|
+
protocol: this.protocol(),
|
|
309
|
+
cookies: this.cookiesList(),
|
|
310
|
+
hostname: this.hostname(),
|
|
311
|
+
ip: this.ip(),
|
|
312
|
+
subdomains: this.ctx?.subdomains || {},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { Macroable } from '@poppinss/macroable';
|
|
4
|
+
import type Encryption from '@adonisjs/encryption';
|
|
5
|
+
import { ServerResponse, IncomingMessage } from 'node:http';
|
|
6
|
+
import type { Qs } from './qs.js';
|
|
7
|
+
import { Redirect } from './redirect.js';
|
|
8
|
+
import type { Router } from './router/main.js';
|
|
9
|
+
import type { HttpContext } from './http_context/main.js';
|
|
10
|
+
import type { CastableHeader, CookieOptions, ResponseConfig, ResponseStream } from './types/response.js';
|
|
11
|
+
export declare class Response extends Macroable {
|
|
12
|
+
#private;
|
|
13
|
+
request: IncomingMessage;
|
|
14
|
+
response: ServerResponse;
|
|
15
|
+
get hasLazyBody(): boolean;
|
|
16
|
+
get isStreamResponse(): boolean;
|
|
17
|
+
lazyBody: Partial<{
|
|
18
|
+
content: [any, boolean, string?];
|
|
19
|
+
stream: [ResponseStream, ((error: NodeJS.ErrnoException) => [string, number?])?];
|
|
20
|
+
fileToStream: [string, boolean, ((error: NodeJS.ErrnoException) => [string, number?])?];
|
|
21
|
+
}>;
|
|
22
|
+
ctx?: HttpContext;
|
|
23
|
+
constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: ResponseConfig, router: Router, qs: Qs);
|
|
24
|
+
get finished(): boolean;
|
|
25
|
+
get headersSent(): boolean;
|
|
26
|
+
get isPending(): boolean;
|
|
27
|
+
protected writeBody(content: any, generateEtag: boolean, jsonpCallbackName?: string): void;
|
|
28
|
+
protected streamBody(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
|
|
29
|
+
protected streamFileForDownload(filePath: string, generateEtag: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
|
|
30
|
+
flushHeaders(statusCode?: number): this;
|
|
31
|
+
getHeader(key: string): import("http").OutgoingHttpHeader | undefined;
|
|
32
|
+
getHeaders(): {
|
|
33
|
+
[x: string]: import("http").OutgoingHttpHeader | undefined;
|
|
34
|
+
};
|
|
35
|
+
header(key: string, value: CastableHeader): this;
|
|
36
|
+
append(key: string, value: CastableHeader): this;
|
|
37
|
+
safeHeader(key: string, value: CastableHeader): this;
|
|
38
|
+
removeHeader(key: string): this;
|
|
39
|
+
getStatus(): number;
|
|
40
|
+
status(code: number): this;
|
|
41
|
+
safeStatus(code: number): this;
|
|
42
|
+
type(type: string, charset?: string): this;
|
|
43
|
+
vary(field: string | string[]): this;
|
|
44
|
+
setEtag(body: any, weak?: boolean): this;
|
|
45
|
+
fresh(): boolean;
|
|
46
|
+
getBody(): any;
|
|
47
|
+
send(body: any, generateEtag?: boolean): void;
|
|
48
|
+
json(body: any, generateEtag?: boolean): void;
|
|
49
|
+
jsonp(body: any, callbackName?: string, generateEtag?: boolean): void;
|
|
50
|
+
stream(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
51
|
+
download(filePath: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
52
|
+
attachment(filePath: string, name?: string, disposition?: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
|
|
53
|
+
location(url: string): this;
|
|
54
|
+
redirect(): Redirect;
|
|
55
|
+
redirect(path: string, forwardQueryString?: boolean, statusCode?: number): void;
|
|
56
|
+
abort(body: any, status?: number): never;
|
|
57
|
+
abortIf(condition: unknown, body: any, status?: number): asserts condition is undefined | null | false;
|
|
58
|
+
abortUnless<T>(condition: T, body: any, status?: number): asserts condition is Exclude<T, undefined | null | false>;
|
|
59
|
+
cookie(key: string, value: any, options?: Partial<CookieOptions>): this;
|
|
60
|
+
encryptedCookie(key: string, value: any, options?: Partial<CookieOptions>): this;
|
|
61
|
+
plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
|
|
62
|
+
encode: boolean;
|
|
63
|
+
}>): this;
|
|
64
|
+
clearCookie(key: string, options?: Partial<CookieOptions>): this;
|
|
65
|
+
finish(): void;
|
|
66
|
+
continue(): void;
|
|
67
|
+
switchingProtocols(): void;
|
|
68
|
+
ok(body: any, generateEtag?: boolean): void;
|
|
69
|
+
created(body?: any, generateEtag?: boolean): void;
|
|
70
|
+
accepted(body: any, generateEtag?: boolean): void;
|
|
71
|
+
nonAuthoritativeInformation(body: any, generateEtag?: boolean): void;
|
|
72
|
+
noContent(): void;
|
|
73
|
+
resetContent(): void;
|
|
74
|
+
partialContent(body: any, generateEtag?: boolean): void;
|
|
75
|
+
multipleChoices(body?: any, generateEtag?: boolean): void;
|
|
76
|
+
movedPermanently(body?: any, generateEtag?: boolean): void;
|
|
77
|
+
movedTemporarily(body?: any, generateEtag?: boolean): void;
|
|
78
|
+
seeOther(body?: any, generateEtag?: boolean): void;
|
|
79
|
+
notModified(body?: any, generateEtag?: boolean): void;
|
|
80
|
+
useProxy(body?: any, generateEtag?: boolean): void;
|
|
81
|
+
temporaryRedirect(body?: any, generateEtag?: boolean): void;
|
|
82
|
+
badRequest(body?: any, generateEtag?: boolean): void;
|
|
83
|
+
unauthorized(body?: any, generateEtag?: boolean): void;
|
|
84
|
+
paymentRequired(body?: any, generateEtag?: boolean): void;
|
|
85
|
+
forbidden(body?: any, generateEtag?: boolean): void;
|
|
86
|
+
notFound(body?: any, generateEtag?: boolean): void;
|
|
87
|
+
methodNotAllowed(body?: any, generateEtag?: boolean): void;
|
|
88
|
+
notAcceptable(body?: any, generateEtag?: boolean): void;
|
|
89
|
+
proxyAuthenticationRequired(body?: any, generateEtag?: boolean): void;
|
|
90
|
+
requestTimeout(body?: any, generateEtag?: boolean): void;
|
|
91
|
+
conflict(body?: any, generateEtag?: boolean): void;
|
|
92
|
+
gone(body?: any, generateEtag?: boolean): void;
|
|
93
|
+
lengthRequired(body?: any, generateEtag?: boolean): void;
|
|
94
|
+
preconditionFailed(body?: any, generateEtag?: boolean): void;
|
|
95
|
+
requestEntityTooLarge(body?: any, generateEtag?: boolean): void;
|
|
96
|
+
requestUriTooLong(body?: any, generateEtag?: boolean): void;
|
|
97
|
+
unsupportedMediaType(body?: any, generateEtag?: boolean): void;
|
|
98
|
+
requestedRangeNotSatisfiable(body?: any, generateEtag?: boolean): void;
|
|
99
|
+
expectationFailed(body?: any, generateEtag?: boolean): void;
|
|
100
|
+
unprocessableEntity(body?: any, generateEtag?: boolean): void;
|
|
101
|
+
tooManyRequests(body?: any, generateEtag?: boolean): void;
|
|
102
|
+
internalServerError(body?: any, generateEtag?: boolean): void;
|
|
103
|
+
notImplemented(body?: any, generateEtag?: boolean): void;
|
|
104
|
+
badGateway(body?: any, generateEtag?: boolean): void;
|
|
105
|
+
serviceUnavailable(body?: any, generateEtag?: boolean): void;
|
|
106
|
+
gatewayTimeout(body?: any, generateEtag?: boolean): void;
|
|
107
|
+
httpVersionNotSupported(body?: any, generateEtag?: boolean): void;
|
|
108
|
+
}
|