@adonisjs/http-server 7.0.0-1 → 7.0.0-3
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/build/chunk-NC6OWANS.js +4437 -0
- package/build/chunk-NC6OWANS.js.map +1 -0
- package/build/factories/http_server.d.ts +1 -0
- package/build/factories/main.js +332 -14
- package/build/factories/main.js.map +1 -0
- package/build/index.js +309 -22
- package/build/index.js.map +1 -0
- package/build/src/define_middleware.d.ts +2 -1
- package/build/src/router/lookup_store/main.d.ts +1 -3
- package/build/src/router/lookup_store/route_finder.d.ts +5 -1
- package/build/src/router/main.d.ts +5 -4
- package/build/src/router/resource.d.ts +19 -7
- package/build/src/types/main.js +1 -15
- package/build/src/types/main.js.map +1 -0
- package/build/src/types/middleware.d.ts +3 -1
- package/package.json +60 -59
- package/build/factories/http_context.js +0 -51
- package/build/factories/http_server.js +0 -26
- package/build/factories/qs_parser_factory.js +0 -44
- package/build/factories/request.js +0 -73
- package/build/factories/response.js +0 -77
- package/build/factories/router.js +0 -45
- package/build/factories/server_factory.js +0 -65
- package/build/src/cookies/client.js +0 -84
- package/build/src/cookies/drivers/encrypted.js +0 -36
- package/build/src/cookies/drivers/plain.js +0 -33
- package/build/src/cookies/drivers/signed.js +0 -36
- package/build/src/cookies/parser.js +0 -167
- package/build/src/cookies/serializer.js +0 -79
- package/build/src/debug.js +0 -10
- package/build/src/define_config.js +0 -68
- package/build/src/define_middleware.js +0 -35
- package/build/src/exception_handler.js +0 -306
- package/build/src/exceptions.js +0 -38
- package/build/src/helpers.js +0 -105
- package/build/src/http_context/local_storage.js +0 -39
- package/build/src/http_context/main.js +0 -105
- package/build/src/qs.js +0 -25
- package/build/src/redirect.js +0 -140
- package/build/src/request.js +0 -865
- package/build/src/response.js +0 -1208
- package/build/src/router/brisk.js +0 -85
- package/build/src/router/executor.js +0 -30
- package/build/src/router/factories/use_return_value.js +0 -22
- package/build/src/router/group.js +0 -207
- package/build/src/router/lookup_store/main.js +0 -86
- package/build/src/router/lookup_store/route_finder.js +0 -49
- package/build/src/router/lookup_store/url_builder.js +0 -209
- package/build/src/router/main.js +0 -316
- package/build/src/router/matchers.js +0 -36
- package/build/src/router/parser.js +0 -17
- package/build/src/router/resource.js +0 -216
- package/build/src/router/route.js +0 -293
- package/build/src/router/store.js +0 -195
- package/build/src/server/factories/final_handler.js +0 -30
- package/build/src/server/factories/middleware_handler.js +0 -16
- package/build/src/server/factories/write_response.js +0 -24
- package/build/src/server/main.js +0 -292
- package/build/src/types/base.js +0 -9
- package/build/src/types/middleware.js +0 -9
- package/build/src/types/qs.js +0 -9
- package/build/src/types/request.js +0 -9
- package/build/src/types/response.js +0 -9
- package/build/src/types/route.js +0 -9
- package/build/src/types/server.js +0 -9
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-3",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
|
-
"build
|
|
9
|
-
"build/
|
|
10
|
-
"build/
|
|
11
|
-
"build/index.js"
|
|
8
|
+
"build",
|
|
9
|
+
"!build/bin",
|
|
10
|
+
"!build/tests"
|
|
12
11
|
],
|
|
13
12
|
"exports": {
|
|
14
13
|
".": "./build/index.js",
|
|
@@ -23,7 +22,8 @@
|
|
|
23
22
|
"test": "cross-env NODE_DEBUG=adonisjs:http c8 npm run quick:test",
|
|
24
23
|
"clean": "del-cli build",
|
|
25
24
|
"typecheck": "tsc --noEmit",
|
|
26
|
-
"
|
|
25
|
+
"precompile": "npm run lint && npm run clean",
|
|
26
|
+
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
27
27
|
"build": "npm run compile",
|
|
28
28
|
"prebenchmark": "npm run build",
|
|
29
29
|
"benchmark": "node benchmarks/index.js",
|
|
@@ -43,70 +43,70 @@
|
|
|
43
43
|
"author": "virk,adonisjs",
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@adonisjs/application": "^8.0.0-
|
|
47
|
-
"@adonisjs/encryption": "^5.1.2-
|
|
48
|
-
"@adonisjs/eslint-config": "^1.
|
|
49
|
-
"@adonisjs/events": "^9.0.0-
|
|
50
|
-
"@adonisjs/fold": "^9.9.3-
|
|
51
|
-
"@adonisjs/logger": "^5.4.2-
|
|
52
|
-
"@adonisjs/prettier-config": "^1.
|
|
53
|
-
"@adonisjs/tsconfig": "^1.
|
|
54
|
-
"@commitlint/cli": "^
|
|
55
|
-
"@commitlint/config-conventional": "^
|
|
46
|
+
"@adonisjs/application": "^8.0.0-3",
|
|
47
|
+
"@adonisjs/encryption": "^5.1.2-5",
|
|
48
|
+
"@adonisjs/eslint-config": "^1.2.0",
|
|
49
|
+
"@adonisjs/events": "^9.0.0-2",
|
|
50
|
+
"@adonisjs/fold": "^9.9.3-12",
|
|
51
|
+
"@adonisjs/logger": "^5.4.2-8",
|
|
52
|
+
"@adonisjs/prettier-config": "^1.2.0",
|
|
53
|
+
"@adonisjs/tsconfig": "^1.2.0",
|
|
54
|
+
"@commitlint/cli": "^18.4.3",
|
|
55
|
+
"@commitlint/config-conventional": "^18.4.3",
|
|
56
56
|
"@fastify/middie": "^8.3.0",
|
|
57
|
-
"@japa/assert": "^2.
|
|
58
|
-
"@japa/expect-type": "^2.0.
|
|
59
|
-
"@japa/runner": "^3.
|
|
60
|
-
"@swc/core": "1.3.
|
|
61
|
-
"@types/accepts": "^1.3.
|
|
62
|
-
"@types/content-disposition": "^0.5.
|
|
63
|
-
"@types/cookie": "^0.
|
|
64
|
-
"@types/destroy": "^1.0.
|
|
65
|
-
"@types/encodeurl": "^1.0.
|
|
66
|
-
"@types/etag": "^1.8.
|
|
67
|
-
"@types/fresh": "^0.5.
|
|
68
|
-
"@types/fs-extra": "^11.0.
|
|
57
|
+
"@japa/assert": "^2.1.0",
|
|
58
|
+
"@japa/expect-type": "^2.0.1",
|
|
59
|
+
"@japa/runner": "^3.1.1",
|
|
60
|
+
"@swc/core": "^1.3.101",
|
|
61
|
+
"@types/accepts": "^1.3.7",
|
|
62
|
+
"@types/content-disposition": "^0.5.8",
|
|
63
|
+
"@types/cookie": "^0.6.0",
|
|
64
|
+
"@types/destroy": "^1.0.3",
|
|
65
|
+
"@types/encodeurl": "^1.0.2",
|
|
66
|
+
"@types/etag": "^1.8.3",
|
|
67
|
+
"@types/fresh": "^0.5.2",
|
|
68
|
+
"@types/fs-extra": "^11.0.4",
|
|
69
69
|
"@types/http-status-codes": "^1.2.0",
|
|
70
|
-
"@types/mime-types": "^2.1.
|
|
71
|
-
"@types/node": "^20.
|
|
72
|
-
"@types/on-finished": "^2.3.
|
|
73
|
-
"@types/pem": "^1.14.
|
|
74
|
-
"@types/proxy-addr": "^2.0.
|
|
75
|
-
"@types/qs": "^6.9.
|
|
76
|
-
"@types/supertest": "^2.0.
|
|
77
|
-
"@types/type-is": "^1.6.
|
|
78
|
-
"@types/vary": "^1.1.
|
|
70
|
+
"@types/mime-types": "^2.1.4",
|
|
71
|
+
"@types/node": "^20.10.5",
|
|
72
|
+
"@types/on-finished": "^2.3.4",
|
|
73
|
+
"@types/pem": "^1.14.4",
|
|
74
|
+
"@types/proxy-addr": "^2.0.3",
|
|
75
|
+
"@types/qs": "^6.9.10",
|
|
76
|
+
"@types/supertest": "^2.0.16",
|
|
77
|
+
"@types/type-is": "^1.6.6",
|
|
78
|
+
"@types/vary": "^1.1.3",
|
|
79
79
|
"@vinejs/vine": "^1.6.0",
|
|
80
|
-
"autocannon": "^7.
|
|
80
|
+
"autocannon": "^7.14.0",
|
|
81
81
|
"c8": "^8.0.1",
|
|
82
82
|
"cross-env": "^7.0.3",
|
|
83
83
|
"del-cli": "^5.1.0",
|
|
84
|
-
"eslint": "^8.
|
|
85
|
-
"fastify": "^4.
|
|
86
|
-
"fs-extra": "^11.
|
|
84
|
+
"eslint": "^8.56.0",
|
|
85
|
+
"fastify": "^4.25.1",
|
|
86
|
+
"fs-extra": "^11.2.0",
|
|
87
87
|
"get-port": "^7.0.0",
|
|
88
88
|
"github-label-sync": "^2.3.1",
|
|
89
89
|
"http-status-codes": "^2.3.0",
|
|
90
90
|
"husky": "^8.0.3",
|
|
91
|
-
"np": "^
|
|
91
|
+
"np": "^9.2.0",
|
|
92
92
|
"pem": "^1.14.8",
|
|
93
|
-
"prettier": "^3.
|
|
94
|
-
"reflect-metadata": "^0.1
|
|
93
|
+
"prettier": "^3.1.1",
|
|
94
|
+
"reflect-metadata": "^0.2.1",
|
|
95
95
|
"supertest": "^6.3.3",
|
|
96
|
-
"ts-node": "^10.9.
|
|
97
|
-
"tsup": "^
|
|
98
|
-
"typescript": "^5.
|
|
96
|
+
"ts-node": "^10.9.2",
|
|
97
|
+
"tsup": "^8.0.1",
|
|
98
|
+
"typescript": "^5.3.3"
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
101
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
102
|
-
"@poppinss/macroable": "^1.0.
|
|
102
|
+
"@poppinss/macroable": "^1.0.1",
|
|
103
103
|
"@poppinss/matchit": "^3.1.2",
|
|
104
|
-
"@poppinss/middleware": "^3.2.
|
|
105
|
-
"@poppinss/utils": "^6.
|
|
106
|
-
"@sindresorhus/is": "^6.0
|
|
104
|
+
"@poppinss/middleware": "^3.2.2",
|
|
105
|
+
"@poppinss/utils": "^6.7.0",
|
|
106
|
+
"@sindresorhus/is": "^6.1.0",
|
|
107
107
|
"accepts": "^1.3.8",
|
|
108
108
|
"content-disposition": "^0.5.4",
|
|
109
|
-
"cookie": "^0.
|
|
109
|
+
"cookie": "^0.6.0",
|
|
110
110
|
"destroy": "^1.2.0",
|
|
111
111
|
"encodeurl": "^1.0.2",
|
|
112
112
|
"etag": "^1.8.1",
|
|
@@ -118,14 +118,14 @@
|
|
|
118
118
|
"tmp-cache": "^1.1.0",
|
|
119
119
|
"type-is": "^1.6.18",
|
|
120
120
|
"vary": "^1.1.2",
|
|
121
|
-
"youch": "^3.3.
|
|
121
|
+
"youch": "^3.3.3"
|
|
122
122
|
},
|
|
123
123
|
"peerDependencies": {
|
|
124
|
-
"@adonisjs/application": "^8.0.0-
|
|
125
|
-
"@adonisjs/encryption": "^5.1.2-
|
|
126
|
-
"@adonisjs/events": "^9.0.0-
|
|
127
|
-
"@adonisjs/fold": "^9.9.3-
|
|
128
|
-
"@adonisjs/logger": "^5.4.2-
|
|
124
|
+
"@adonisjs/application": "^8.0.0-3",
|
|
125
|
+
"@adonisjs/encryption": "^5.1.2-5",
|
|
126
|
+
"@adonisjs/events": "^9.0.0-2",
|
|
127
|
+
"@adonisjs/fold": "^9.9.3-12",
|
|
128
|
+
"@adonisjs/logger": "^5.4.2-8"
|
|
129
129
|
},
|
|
130
130
|
"repository": {
|
|
131
131
|
"type": "git",
|
|
@@ -174,7 +174,8 @@
|
|
|
174
174
|
"outDir": "./build",
|
|
175
175
|
"clean": true,
|
|
176
176
|
"format": "esm",
|
|
177
|
-
"dts":
|
|
177
|
+
"dts": false,
|
|
178
|
+
"sourcemap": true,
|
|
178
179
|
"target": "esnext"
|
|
179
180
|
}
|
|
180
181
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Container } from '@adonisjs/fold';
|
|
10
|
-
import { LoggerFactory } from '@adonisjs/logger/factories';
|
|
11
|
-
import { RequestFactory } from './request.js';
|
|
12
|
-
import { ResponseFactory } from './response.js';
|
|
13
|
-
import { HttpContext } from '../src/http_context/main.js';
|
|
14
|
-
/**
|
|
15
|
-
* HttpContext factory is used to generate Http context class instances for
|
|
16
|
-
* testing
|
|
17
|
-
*/
|
|
18
|
-
export class HttpContextFactory {
|
|
19
|
-
#parameters = {};
|
|
20
|
-
/**
|
|
21
|
-
* Returns the request class instance
|
|
22
|
-
*/
|
|
23
|
-
#createRequest() {
|
|
24
|
-
return this.#parameters.request || new RequestFactory().create();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns the response class instance
|
|
28
|
-
*/
|
|
29
|
-
#createResponse() {
|
|
30
|
-
return this.#parameters.response || new ResponseFactory().create();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns an instance of the logger class
|
|
34
|
-
*/
|
|
35
|
-
#createLogger() {
|
|
36
|
-
return this.#parameters.logger || new LoggerFactory().create();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Merge factory params
|
|
40
|
-
*/
|
|
41
|
-
merge(params) {
|
|
42
|
-
Object.assign(this.#parameters, params);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Create request
|
|
47
|
-
*/
|
|
48
|
-
create() {
|
|
49
|
-
return new HttpContext(this.#createRequest(), this.#createResponse(), this.#createLogger(), new Container().createResolver());
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import getPort from 'get-port';
|
|
10
|
-
import { getActiveTest } from '@japa/runner';
|
|
11
|
-
import { createServer } from 'node:http';
|
|
12
|
-
export const httpServer = {
|
|
13
|
-
async create(handler) {
|
|
14
|
-
const server = createServer(handler);
|
|
15
|
-
const test = getActiveTest();
|
|
16
|
-
test?.cleanup(() => {
|
|
17
|
-
server.close();
|
|
18
|
-
});
|
|
19
|
-
const port = await getPort({ port: 3000 });
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
server.listen(port, 'localhost', () => {
|
|
22
|
-
return resolve({ server, port, url: `http://localhost:${port}` });
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Qs } from '../src/qs.js';
|
|
10
|
-
/**
|
|
11
|
-
* QS Parser factory is used to generate the query string
|
|
12
|
-
* parser for testing
|
|
13
|
-
*/
|
|
14
|
-
export class QsParserFactory {
|
|
15
|
-
#options = {
|
|
16
|
-
parse: {
|
|
17
|
-
depth: 5,
|
|
18
|
-
parameterLimit: 1000,
|
|
19
|
-
allowSparse: false,
|
|
20
|
-
arrayLimit: 20,
|
|
21
|
-
comma: true,
|
|
22
|
-
},
|
|
23
|
-
stringify: {
|
|
24
|
-
encode: true,
|
|
25
|
-
encodeValuesOnly: false,
|
|
26
|
-
arrayFormat: 'indices',
|
|
27
|
-
skipNulls: false,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Merge encryption factory options
|
|
32
|
-
*/
|
|
33
|
-
merge(options) {
|
|
34
|
-
Object.assign(this.#options.parse, options.parse);
|
|
35
|
-
Object.assign(this.#options.stringify, options.stringify);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create instance of the logger class
|
|
40
|
-
*/
|
|
41
|
-
create() {
|
|
42
|
-
return new Qs(this.#options);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Socket } from 'node:net';
|
|
10
|
-
import proxyAddr from 'proxy-addr';
|
|
11
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
12
|
-
import { EncryptionFactory } from '@adonisjs/encryption/factories';
|
|
13
|
-
import { Request } from '../src/request.js';
|
|
14
|
-
import { QsParserFactory } from './qs_parser_factory.js';
|
|
15
|
-
/**
|
|
16
|
-
* Request factory is used to generate request class instances for
|
|
17
|
-
* testing
|
|
18
|
-
*/
|
|
19
|
-
export class RequestFactory {
|
|
20
|
-
#parameters = {};
|
|
21
|
-
/**
|
|
22
|
-
* Returns the config for the request class
|
|
23
|
-
*/
|
|
24
|
-
#getConfig() {
|
|
25
|
-
return {
|
|
26
|
-
allowMethodSpoofing: false,
|
|
27
|
-
trustProxy: proxyAddr.compile('loopback'),
|
|
28
|
-
subdomainOffset: 2,
|
|
29
|
-
generateRequestId: false,
|
|
30
|
-
...this.#parameters.config,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns the HTTP req object
|
|
35
|
-
*/
|
|
36
|
-
#createRequest() {
|
|
37
|
-
const req = this.#parameters.req || new IncomingMessage(new Socket());
|
|
38
|
-
if (this.#parameters.url) {
|
|
39
|
-
req.url = this.#parameters.url;
|
|
40
|
-
}
|
|
41
|
-
if (this.#parameters.method) {
|
|
42
|
-
req.method = this.#parameters.method;
|
|
43
|
-
}
|
|
44
|
-
return req;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Returns the HTTP res object
|
|
48
|
-
*/
|
|
49
|
-
#createResponse(req) {
|
|
50
|
-
return this.#parameters.res || new ServerResponse(req);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns an instance of the encryptor to encrypt
|
|
54
|
-
* signed URLs
|
|
55
|
-
*/
|
|
56
|
-
#createEncryption() {
|
|
57
|
-
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Merge factory params
|
|
61
|
-
*/
|
|
62
|
-
merge(params) {
|
|
63
|
-
Object.assign(this.#parameters, params);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Create request
|
|
68
|
-
*/
|
|
69
|
-
create() {
|
|
70
|
-
const req = this.#createRequest();
|
|
71
|
-
return new Request(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), new QsParserFactory().create());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Socket } from 'node:net';
|
|
10
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
11
|
-
import { EncryptionFactory } from '@adonisjs/encryption/factories';
|
|
12
|
-
import { RouterFactory } from './router.js';
|
|
13
|
-
import { Response } from '../src/response.js';
|
|
14
|
-
import { QsParserFactory } from './qs_parser_factory.js';
|
|
15
|
-
/**
|
|
16
|
-
* Response factory is used to generate response class instances for
|
|
17
|
-
* testing
|
|
18
|
-
*/
|
|
19
|
-
export class ResponseFactory {
|
|
20
|
-
#parameters = {};
|
|
21
|
-
/**
|
|
22
|
-
* Returns the config for the request class
|
|
23
|
-
*/
|
|
24
|
-
#getConfig() {
|
|
25
|
-
return {
|
|
26
|
-
etag: false,
|
|
27
|
-
jsonpCallbackName: 'callback',
|
|
28
|
-
cookie: {
|
|
29
|
-
maxAge: 90,
|
|
30
|
-
path: '/',
|
|
31
|
-
httpOnly: true,
|
|
32
|
-
sameSite: false,
|
|
33
|
-
secure: false,
|
|
34
|
-
},
|
|
35
|
-
...this.#parameters.config,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Returns the HTTP req object
|
|
40
|
-
*/
|
|
41
|
-
#createRequest() {
|
|
42
|
-
return this.#parameters.req || new IncomingMessage(new Socket());
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns an instance of the router
|
|
46
|
-
*/
|
|
47
|
-
#createRouter() {
|
|
48
|
-
return this.#parameters.router || new RouterFactory().create();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns the HTTP res object
|
|
52
|
-
*/
|
|
53
|
-
#createResponse(req) {
|
|
54
|
-
return this.#parameters.res || new ServerResponse(req);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Returns an instance of the encryptor to encrypt
|
|
58
|
-
* signed URLs
|
|
59
|
-
*/
|
|
60
|
-
#createEncryption() {
|
|
61
|
-
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Merge factory params
|
|
65
|
-
*/
|
|
66
|
-
merge(params) {
|
|
67
|
-
Object.assign(this.#parameters, params);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Create response class instance
|
|
72
|
-
*/
|
|
73
|
-
create() {
|
|
74
|
-
const req = this.#createRequest();
|
|
75
|
-
return new Response(req, this.#createResponse(req), this.#createEncryption(), this.#getConfig(), this.#createRouter(), new QsParserFactory().create());
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { AppFactory } from '@adonisjs/application/factories';
|
|
10
|
-
import { EncryptionFactory } from '@adonisjs/encryption/factories';
|
|
11
|
-
import { Router } from '../src/router/main.js';
|
|
12
|
-
import { QsParserFactory } from './qs_parser_factory.js';
|
|
13
|
-
/**
|
|
14
|
-
* Router factory is used to generate router class instances for
|
|
15
|
-
* testing
|
|
16
|
-
*/
|
|
17
|
-
export class RouterFactory {
|
|
18
|
-
#parameters = {};
|
|
19
|
-
/**
|
|
20
|
-
* Returns an instance of the application class
|
|
21
|
-
*/
|
|
22
|
-
#getApp() {
|
|
23
|
-
return (this.#parameters.app || new AppFactory().create(new URL('./app/', import.meta.url), () => { }));
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns an instance of the encryptor to encrypt
|
|
27
|
-
* signed URLs
|
|
28
|
-
*/
|
|
29
|
-
#createEncryption() {
|
|
30
|
-
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Merge factory params
|
|
34
|
-
*/
|
|
35
|
-
merge(params) {
|
|
36
|
-
Object.assign(this.#parameters, params);
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Create router instance
|
|
41
|
-
*/
|
|
42
|
-
create() {
|
|
43
|
-
return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { Logger } from '@adonisjs/logger';
|
|
10
|
-
import { Emitter } from '@adonisjs/events';
|
|
11
|
-
import { AppFactory } from '@adonisjs/application/factories';
|
|
12
|
-
import { EncryptionFactory } from '@adonisjs/encryption/factories';
|
|
13
|
-
import { Server } from '../src/server/main.js';
|
|
14
|
-
import { defineConfig } from '../src/define_config.js';
|
|
15
|
-
/**
|
|
16
|
-
* Server factory is used to generate server class instances for
|
|
17
|
-
* testing
|
|
18
|
-
*/
|
|
19
|
-
export class ServerFactory {
|
|
20
|
-
#parameters = {};
|
|
21
|
-
/**
|
|
22
|
-
* Returns the emitter instance
|
|
23
|
-
*/
|
|
24
|
-
#getEmitter() {
|
|
25
|
-
return this.#parameters.emitter || new Emitter(this.#getApp());
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns the logger instance
|
|
29
|
-
*/
|
|
30
|
-
#getLogger() {
|
|
31
|
-
return this.#parameters.logger || new Logger({ enabled: false });
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns the config for the server class
|
|
35
|
-
*/
|
|
36
|
-
#getConfig() {
|
|
37
|
-
return defineConfig(this.#parameters.config || {});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns an instance of the application class
|
|
41
|
-
*/
|
|
42
|
-
#getApp() {
|
|
43
|
-
return (this.#parameters.app || new AppFactory().create(new URL('./app/', import.meta.url), () => { }));
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Returns an instance of the encryptor to encrypt
|
|
47
|
-
* signed URLs
|
|
48
|
-
*/
|
|
49
|
-
#createEncryption() {
|
|
50
|
-
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Merge factory params
|
|
54
|
-
*/
|
|
55
|
-
merge(params) {
|
|
56
|
-
Object.assign(this.#parameters, params);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Create server instance
|
|
61
|
-
*/
|
|
62
|
-
create() {
|
|
63
|
-
return new Server(this.#getApp(), this.#createEncryption(), this.#getEmitter(), this.#getLogger(), this.#getConfig());
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import * as plainCookiesDriver from './drivers/plain.js';
|
|
10
|
-
import * as signedCookiesDriver from './drivers/signed.js';
|
|
11
|
-
import * as encryptedCookiesDriver from './drivers/encrypted.js';
|
|
12
|
-
/**
|
|
13
|
-
* Cookie client exposes the API to parse/set AdonisJS cookies
|
|
14
|
-
* as a client.
|
|
15
|
-
*/
|
|
16
|
-
export class CookieClient {
|
|
17
|
-
#encryption;
|
|
18
|
-
constructor(encryption) {
|
|
19
|
-
this.#encryption = encryption;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Encrypt a key value pair to be sent in the cookie header
|
|
23
|
-
*/
|
|
24
|
-
encrypt(key, value) {
|
|
25
|
-
return encryptedCookiesDriver.pack(key, value, this.#encryption);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Sign a key value pair to be sent in the cookie header
|
|
29
|
-
*/
|
|
30
|
-
sign(key, value) {
|
|
31
|
-
return signedCookiesDriver.pack(key, value, this.#encryption);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Encode a key value pair to be sent in the cookie header
|
|
35
|
-
*/
|
|
36
|
-
encode(_, value) {
|
|
37
|
-
return plainCookiesDriver.pack(value);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Unsign a signed cookie value
|
|
41
|
-
*/
|
|
42
|
-
unsign(key, value) {
|
|
43
|
-
return signedCookiesDriver.canUnpack(value)
|
|
44
|
-
? signedCookiesDriver.unpack(key, value, this.#encryption)
|
|
45
|
-
: null;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Decrypt an encrypted cookie value
|
|
49
|
-
*/
|
|
50
|
-
decrypt(key, value) {
|
|
51
|
-
return encryptedCookiesDriver.canUnpack(value)
|
|
52
|
-
? encryptedCookiesDriver.unpack(key, value, this.#encryption)
|
|
53
|
-
: null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Decode an encoded cookie value
|
|
57
|
-
*/
|
|
58
|
-
decode(_, value) {
|
|
59
|
-
return plainCookiesDriver.canUnpack(value) ? plainCookiesDriver.unpack(value) : null;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Parse response cookie
|
|
63
|
-
*/
|
|
64
|
-
parse(key, value) {
|
|
65
|
-
/**
|
|
66
|
-
* Unsign signed cookie
|
|
67
|
-
*/
|
|
68
|
-
if (signedCookiesDriver.canUnpack(value)) {
|
|
69
|
-
return signedCookiesDriver.unpack(key, value, this.#encryption);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Decrypted encrypted cookie
|
|
73
|
-
*/
|
|
74
|
-
if (encryptedCookiesDriver.canUnpack(value)) {
|
|
75
|
-
return encryptedCookiesDriver.unpack(key, value, this.#encryption);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Decode encoded cookie
|
|
79
|
-
*/
|
|
80
|
-
if (plainCookiesDriver.canUnpack(value)) {
|
|
81
|
-
return plainCookiesDriver.unpack(value);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Encrypt a value to be set as cookie
|
|
11
|
-
*/
|
|
12
|
-
export function pack(key, value, encryption) {
|
|
13
|
-
if (value === undefined || value === null) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return `e:${encryption.encrypt(value, undefined, key)}`;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Returns a boolean, if the unpack method from this module can attempt
|
|
20
|
-
* to unpack encrypted value.
|
|
21
|
-
*/
|
|
22
|
-
export function canUnpack(encryptedValue) {
|
|
23
|
-
return typeof encryptedValue === 'string' && encryptedValue.substring(0, 2) === 'e:';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
|
|
27
|
-
* Only call this method, when `canUnpack` returns true, otherwise runtime
|
|
28
|
-
* exceptions can be raised.
|
|
29
|
-
*/
|
|
30
|
-
export function unpack(key, encryptedValue, encryption) {
|
|
31
|
-
const value = encryptedValue.slice(2);
|
|
32
|
-
if (!value) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return encryption.decrypt(value, key);
|
|
36
|
-
}
|