@opra/http 1.20.0 → 1.22.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.
Files changed (70) hide show
  1. package/{esm/express-adapter.js → express-adapter.js} +2 -1
  2. package/{esm/http-adapter.js → http-adapter.js} +5 -1
  3. package/{esm/http-context.js → http-context.js} +10 -1
  4. package/{esm/http-handler.js → http-handler.js} +3 -0
  5. package/{esm/impl → impl}/http-incoming.host.js +1 -0
  6. package/{esm/impl → impl}/multipart-reader.js +10 -5
  7. package/{esm/impl → impl}/node-incoming-message.host.js +15 -4
  8. package/{esm/impl → impl}/node-outgoing-message.host.js +7 -2
  9. package/package.json +14 -31
  10. package/{esm/utils → utils}/body-reader.js +10 -2
  11. package/cjs/express-adapter.js +0 -134
  12. package/cjs/http-adapter.js +0 -25
  13. package/cjs/http-context.js +0 -114
  14. package/cjs/http-handler.js +0 -668
  15. package/cjs/impl/http-incoming.host.js +0 -112
  16. package/cjs/impl/http-outgoing.host.js +0 -207
  17. package/cjs/impl/multipart-reader.js +0 -209
  18. package/cjs/impl/node-incoming-message.host.js +0 -115
  19. package/cjs/impl/node-outgoing-message.host.js +0 -201
  20. package/cjs/index.js +0 -27
  21. package/cjs/interfaces/http-incoming.interface.js +0 -25
  22. package/cjs/interfaces/http-outgoing.interface.js +0 -22
  23. package/cjs/interfaces/node-incoming-message.interface.js +0 -65
  24. package/cjs/interfaces/node-outgoing-message.interface.js +0 -15
  25. package/cjs/package.json +0 -3
  26. package/cjs/type-guards.js +0 -27
  27. package/cjs/utils/body-reader.js +0 -227
  28. package/cjs/utils/common.js +0 -67
  29. package/cjs/utils/concat-readable.js +0 -19
  30. package/cjs/utils/convert-to-headers.js +0 -64
  31. package/cjs/utils/convert-to-raw-headers.js +0 -25
  32. package/cjs/utils/match-known-fields.js +0 -49
  33. package/cjs/utils/wrap-exception.js +0 -33
  34. package/esm/package.json +0 -3
  35. package/types/index.d.cts +0 -22
  36. /package/{types/express-adapter.d.ts → express-adapter.d.ts} +0 -0
  37. /package/{types/http-adapter.d.ts → http-adapter.d.ts} +0 -0
  38. /package/{types/http-context.d.ts → http-context.d.ts} +0 -0
  39. /package/{types/http-handler.d.ts → http-handler.d.ts} +0 -0
  40. /package/{types/impl → impl}/http-incoming.host.d.ts +0 -0
  41. /package/{types/impl → impl}/http-outgoing.host.d.ts +0 -0
  42. /package/{esm/impl → impl}/http-outgoing.host.js +0 -0
  43. /package/{types/impl → impl}/multipart-reader.d.ts +0 -0
  44. /package/{types/impl → impl}/node-incoming-message.host.d.ts +0 -0
  45. /package/{types/impl → impl}/node-outgoing-message.host.d.ts +0 -0
  46. /package/{types/index.d.ts → index.d.ts} +0 -0
  47. /package/{esm/index.js → index.js} +0 -0
  48. /package/{types/interfaces → interfaces}/http-incoming.interface.d.ts +0 -0
  49. /package/{esm/interfaces → interfaces}/http-incoming.interface.js +0 -0
  50. /package/{types/interfaces → interfaces}/http-outgoing.interface.d.ts +0 -0
  51. /package/{esm/interfaces → interfaces}/http-outgoing.interface.js +0 -0
  52. /package/{types/interfaces → interfaces}/node-incoming-message.interface.d.ts +0 -0
  53. /package/{esm/interfaces → interfaces}/node-incoming-message.interface.js +0 -0
  54. /package/{types/interfaces → interfaces}/node-outgoing-message.interface.d.ts +0 -0
  55. /package/{esm/interfaces → interfaces}/node-outgoing-message.interface.js +0 -0
  56. /package/{types/type-guards.d.ts → type-guards.d.ts} +0 -0
  57. /package/{esm/type-guards.js → type-guards.js} +0 -0
  58. /package/{types/utils → utils}/body-reader.d.ts +0 -0
  59. /package/{types/utils → utils}/common.d.ts +0 -0
  60. /package/{esm/utils → utils}/common.js +0 -0
  61. /package/{types/utils → utils}/concat-readable.d.ts +0 -0
  62. /package/{esm/utils → utils}/concat-readable.js +0 -0
  63. /package/{types/utils → utils}/convert-to-headers.d.ts +0 -0
  64. /package/{esm/utils → utils}/convert-to-headers.js +0 -0
  65. /package/{types/utils → utils}/convert-to-raw-headers.d.ts +0 -0
  66. /package/{esm/utils → utils}/convert-to-raw-headers.js +0 -0
  67. /package/{types/utils → utils}/match-known-fields.d.ts +0 -0
  68. /package/{esm/utils → utils}/match-known-fields.js +0 -0
  69. /package/{types/utils → utils}/wrap-exception.d.ts +0 -0
  70. /package/{esm/utils → utils}/wrap-exception.js +0 -0
@@ -1,67 +0,0 @@
1
- "use strict";
2
- /*
3
- This file contains code blocks from open source NodeJs project
4
- https://github.com/nodejs/
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validateHeaderValue = exports.validateHeaderName = void 0;
8
- exports.checkIsHttpToken = checkIsHttpToken;
9
- exports.hideStackFrames = hideStackFrames;
10
- exports.validateString = validateString;
11
- const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
12
- const nodeInternalPrefix = '__node_internal_';
13
- /**
14
- * Verifies that the given val is a valid HTTP token
15
- * per the rules defined in RFC 7230
16
- * See https://tools.ietf.org/html/rfc7230#section-3.2.6
17
- *
18
- * https://github.com/nodejs/node/blob/main/lib/_http_common.js
19
- */
20
- function checkIsHttpToken(val) {
21
- return typeof val === 'string' && tokenRegExp.exec(val) !== null;
22
- }
23
- const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
24
- /**
25
- * True if val contains an invalid field-vchar
26
- * field-value = *( field-content / obs-fold )
27
- * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
28
- * field-vchar = VCHAR / obs-text
29
- *
30
- * https://github.com/nodejs/node/blob/main/lib/_http_common.js
31
- */
32
- function checkInvalidHeaderChar(val) {
33
- // noinspection SuspiciousTypeOfGuard
34
- return typeof val === 'string' && headerCharRegex.exec(val) !== null;
35
- }
36
- /**
37
- * This function removes unnecessary frames from Node.js core errors.
38
- *
39
- * https://github.com/nodejs/node/blob/main/lib/internal/errors.js
40
- */
41
- function hideStackFrames(fn) {
42
- // We rename the functions that will be hidden to cut off the stacktrace
43
- // at the outermost one
44
- const hidden = nodeInternalPrefix + fn.name;
45
- // @ts-ignore
46
- Object.defineProperty(fn, 'name', { __proto__: null, value: hidden });
47
- return fn;
48
- }
49
- exports.validateHeaderName = hideStackFrames((name, label) => {
50
- // noinspection SuspiciousTypeOfGuard
51
- if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
52
- throw new TypeError(`${label || 'Header name'} must be a valid HTTP token ["${name}"]`);
53
- }
54
- });
55
- exports.validateHeaderValue = hideStackFrames((name, value) => {
56
- if (value === undefined) {
57
- throw new TypeError(`Invalid value "${value}" for header "${name}"`);
58
- }
59
- if (checkInvalidHeaderChar(value)) {
60
- throw new TypeError(`Invalid character in header content ["${name}"]`);
61
- }
62
- });
63
- function validateString(value, name) {
64
- if (typeof value !== 'string') {
65
- throw new TypeError(`Invalid ${name ? name + ' ' : ''}argument. Value must be a string`);
66
- }
67
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.concatReadable = concatReadable;
4
- const stream_1 = require("stream");
5
- function concatReadable(...streams) {
6
- const out = new stream_1.PassThrough();
7
- const pipeNext = () => {
8
- const nextStream = streams.shift();
9
- if (nextStream) {
10
- nextStream.pipe(out, { end: false });
11
- nextStream.once('end', () => pipeNext());
12
- }
13
- else {
14
- out.end();
15
- }
16
- };
17
- pipeNext();
18
- return out;
19
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToHeaders = convertToHeaders;
4
- exports.convertToHeadersDistinct = convertToHeadersDistinct;
5
- const match_known_fields_js_1 = require("./match-known-fields.js");
6
- function convertToHeaders(src, dst, joinDuplicateHeaders) {
7
- for (let n = 0; n < src.length; n += 2) {
8
- addHeaderLine(src[n], src[n + 1], dst, joinDuplicateHeaders);
9
- }
10
- return dst;
11
- }
12
- function convertToHeadersDistinct(src, dst) {
13
- const count = src.length % 2;
14
- for (let n = 0; n < count; n += 2) {
15
- addHeaderLineDistinct(src[n], src[n + 1], dst);
16
- }
17
- return dst;
18
- }
19
- function addHeaderLine(field, value, dest, joinDuplicateHeaders) {
20
- if (value == null)
21
- return;
22
- field = field.toLowerCase();
23
- const [, flag] = (0, match_known_fields_js_1.matchKnownFields)(field);
24
- // comma(0) or semicolon(2) delimited field
25
- if (flag === match_known_fields_js_1.COMMA_DELIMITED_FIELD || flag === match_known_fields_js_1.SEMICOLON_DELIMITED_FIELD) {
26
- // Make a delimited list
27
- if (typeof dest[field] === 'string') {
28
- dest[field] += (flag === match_known_fields_js_1.COMMA_DELIMITED_FIELD ? ', ' : '; ') + value;
29
- }
30
- else {
31
- dest[field] = value;
32
- }
33
- }
34
- else if (flag === match_known_fields_js_1.ARRAY_FIELD) {
35
- // Array header -- only Set-Cookie at the moment
36
- if (dest['set-cookie'] !== undefined) {
37
- dest['set-cookie'].push(value);
38
- }
39
- else {
40
- dest['set-cookie'] = [value];
41
- }
42
- }
43
- else if (joinDuplicateHeaders) {
44
- if (dest[field] === undefined) {
45
- dest[field] = value;
46
- }
47
- else {
48
- dest[field] += ', ' + value;
49
- }
50
- }
51
- else if (dest[field] === undefined) {
52
- // Drop duplicates
53
- dest[field] = value;
54
- }
55
- }
56
- function addHeaderLineDistinct(field, value, dest) {
57
- field = field.toLowerCase();
58
- if (!dest[field]) {
59
- dest[field] = [value];
60
- }
61
- else {
62
- dest[field].push(value);
63
- }
64
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToRawHeaders = convertToRawHeaders;
4
- const match_known_fields_js_1 = require("./match-known-fields.js");
5
- function convertToRawHeaders(src) {
6
- return Object.entries(src).reduce((a, [field, v]) => {
7
- const [name, flag] = (0, match_known_fields_js_1.matchKnownFields)(field);
8
- if (flag === match_known_fields_js_1.ARRAY_FIELD) {
9
- if (Array.isArray(v))
10
- v.forEach(x => a.push(name, String(x)));
11
- else
12
- a.push(name, String(v));
13
- return a;
14
- }
15
- if (flag === match_known_fields_js_1.COMMA_DELIMITED_FIELD || flag === match_known_fields_js_1.SEMICOLON_DELIMITED_FIELD) {
16
- v = Array.isArray(v)
17
- ? v.join(flag === match_known_fields_js_1.COMMA_DELIMITED_FIELD ? ', ' : '; ')
18
- : String(v);
19
- }
20
- else
21
- v = Array.isArray(v) ? String(v[0]) : String(v);
22
- a.push(name, v);
23
- return a;
24
- }, []);
25
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ARRAY_FIELD = exports.SEMICOLON_DELIMITED_FIELD = exports.COMMA_DELIMITED_FIELD = exports.NO_DUPLICATES_FIELD = void 0;
4
- exports.matchKnownFields = matchKnownFields;
5
- const common_1 = require("@opra/common");
6
- exports.NO_DUPLICATES_FIELD = 0;
7
- exports.COMMA_DELIMITED_FIELD = 1;
8
- exports.SEMICOLON_DELIMITED_FIELD = 2;
9
- exports.ARRAY_FIELD = 3;
10
- const ARRAY_HEADERS = ['set-cookie'];
11
- const NO_DUPLICATES_HEADERS = [
12
- 'age',
13
- 'from',
14
- 'etag',
15
- 'server',
16
- 'referer',
17
- 'referrer',
18
- 'expires',
19
- 'location',
20
- 'user-agent',
21
- 'retry-after',
22
- 'content-type',
23
- 'content-length',
24
- 'max-forwards',
25
- 'last-modified',
26
- 'authorization',
27
- 'proxy-authorization',
28
- 'if-modified-since',
29
- 'if-unmodified-since',
30
- ];
31
- const SEMICOLON_DELIMITED_HEADERS = ['cookie'];
32
- const KNOWN_FIELDS = Object.values(common_1.HttpHeaderCodes).reduce((o, k) => {
33
- const n = k.toLowerCase();
34
- o[n] = [
35
- k,
36
- NO_DUPLICATES_HEADERS.includes(n)
37
- ? exports.NO_DUPLICATES_FIELD
38
- : ARRAY_HEADERS.includes(n)
39
- ? exports.ARRAY_FIELD
40
- : SEMICOLON_DELIMITED_HEADERS.includes(n)
41
- ? exports.SEMICOLON_DELIMITED_FIELD
42
- : exports.COMMA_DELIMITED_FIELD,
43
- ];
44
- return o;
45
- }, {});
46
- function matchKnownFields(field) {
47
- const x = KNOWN_FIELDS[field.toLowerCase()];
48
- return x ? x : [field, exports.COMMA_DELIMITED_FIELD];
49
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapException = wrapException;
4
- const common_1 = require("@opra/common");
5
- function wrapException(error) {
6
- if (error instanceof common_1.OpraHttpError)
7
- return error;
8
- let status = 500;
9
- if (typeof error.status === 'number')
10
- status = error.status;
11
- else if (typeof error.getStatus === 'function')
12
- status = error.getStatus();
13
- switch (status) {
14
- case 400:
15
- return new common_1.BadRequestError(error);
16
- case 401:
17
- return new common_1.UnauthorizedError(error);
18
- case 403:
19
- return new common_1.ForbiddenError(error);
20
- case 404:
21
- return new common_1.NotFoundError(error);
22
- case 405:
23
- return new common_1.MethodNotAllowedError(error);
24
- case 406:
25
- return new common_1.NotAcceptableError(error);
26
- case 422:
27
- return new common_1.UnprocessableEntityError(error);
28
- case 424:
29
- return new common_1.FailedDependencyError(error);
30
- default:
31
- return new common_1.InternalServerError(error);
32
- }
33
- }
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/types/index.d.cts DELETED
@@ -1,22 +0,0 @@
1
- import 'reflect-metadata';
2
- import * as HttpIncomingHost_ from './impl/http-incoming.host.js';
3
- import * as HttpOutgoingHost_ from './impl/http-outgoing.host.js';
4
- import * as NodeIncomingMessageHost_ from './impl/node-incoming-message.host.js';
5
- import * as NodeOutgoingMessageHost_ from './impl/node-outgoing-message.host.js';
6
- export * from './express-adapter.js';
7
- export * from './http-adapter.js';
8
- export * from './http-context.js';
9
- export * from './http-handler.js';
10
- export * from './impl/multipart-reader.js';
11
- export * from './interfaces/http-incoming.interface.js';
12
- export * from './interfaces/http-outgoing.interface.js';
13
- export * from './interfaces/node-incoming-message.interface.js';
14
- export * from './interfaces/node-outgoing-message.interface.js';
15
- export * from './type-guards.js';
16
- export * from './utils/wrap-exception.js';
17
- export declare namespace classes {
18
- export import HttpIncomingHost = HttpIncomingHost_.HttpIncomingHost;
19
- export import HttpOutgoingHost = HttpOutgoingHost_.HttpOutgoingHost;
20
- export import NodeIncomingMessageHost = NodeIncomingMessageHost_.NodeIncomingMessageHost;
21
- export import NodeOutgoingMessageHost = NodeOutgoingMessageHost_.NodeOutgoingMessageHost;
22
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes