@adonisjs/http-server 7.0.0-1 → 7.0.0-2
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-Z63E3STR.js +4436 -0
- package/build/chunk-Z63E3STR.js.map +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/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 +2 -2
- 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/package.json +52 -51
- 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
|
@@ -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
|
-
}
|
|
@@ -1,33 +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 { base64, MessageBuilder } from '@poppinss/utils';
|
|
10
|
-
/**
|
|
11
|
-
* Encodes a value into a base64 url encoded string to
|
|
12
|
-
* be set as cookie
|
|
13
|
-
*/
|
|
14
|
-
export function pack(value) {
|
|
15
|
-
if (value === undefined || value === null) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return base64.urlEncode(new MessageBuilder().build(value));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns true when this `unpack` method of this module can attempt
|
|
22
|
-
* to unpack the encode value.
|
|
23
|
-
*/
|
|
24
|
-
export function canUnpack(encodedValue) {
|
|
25
|
-
return typeof encodedValue === 'string';
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
|
|
29
|
-
* before calling this method
|
|
30
|
-
*/
|
|
31
|
-
export function unpack(encodedValue) {
|
|
32
|
-
return new MessageBuilder().verify(base64.urlDecode(encodedValue, 'utf-8', false));
|
|
33
|
-
}
|
|
@@ -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
|
-
* Signs a value to be shared as a cookie. The signed output has a
|
|
11
|
-
* hash to verify tampering with the original value
|
|
12
|
-
*/
|
|
13
|
-
export function pack(key, value, encryption) {
|
|
14
|
-
if (value === undefined || value === null) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return `s:${encryption.verifier.sign(value, undefined, key)}`;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns a boolean, if the unpack method from this module can attempt
|
|
21
|
-
* to unpack the signed value.
|
|
22
|
-
*/
|
|
23
|
-
export function canUnpack(signedValue) {
|
|
24
|
-
return typeof signedValue === 'string' && signedValue.substring(0, 2) === 's:';
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Attempts to unpack the signed value. Make sure to call `canUnpack` before
|
|
28
|
-
* calling this method.
|
|
29
|
-
*/
|
|
30
|
-
export function unpack(key, signedValue, encryption) {
|
|
31
|
-
const value = signedValue.slice(2);
|
|
32
|
-
if (!value) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return encryption.verifier.unsign(value, key);
|
|
36
|
-
}
|