webhoster 0.3.3 → 0.3.5

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 (157) hide show
  1. package/README.md +4 -4
  2. package/data/CookieObject.js +1 -1
  3. package/{types/index.js → data/custom-types.js} +1 -1
  4. package/{types/typings.d.ts → data/middleware.d.ts} +1 -1
  5. package/helpers/RequestReader.js +1 -1
  6. package/helpers/ResponseHeaders.js +9 -10
  7. package/lib/HttpHandler.js +4 -4
  8. package/lib/HttpRequest.js +2 -2
  9. package/lib/HttpResponse.js +2 -2
  10. package/lib/HttpTransaction.js +2 -2
  11. package/middleware/AutoHeadersMiddleware.js +2 -2
  12. package/middleware/CORSMiddleware.js +3 -3
  13. package/middleware/CaseInsensitiveHeadersMiddleware.js +2 -2
  14. package/middleware/ContentDecoderMiddleware.js +1 -1
  15. package/middleware/ContentEncoderMiddleware.js +2 -2
  16. package/middleware/ContentLengthMiddleware.js +2 -2
  17. package/middleware/HashMiddleware.js +2 -2
  18. package/middleware/HeadMethodMiddleware.js +3 -3
  19. package/middleware/MethodMiddleware.js +3 -3
  20. package/middleware/PathMiddleware.js +4 -4
  21. package/middleware/ReadFormData.js +1 -1
  22. package/middleware/SendJsonMiddleware.js +4 -4
  23. package/middleware/SendStringMiddleware.js +3 -3
  24. package/package.json +21 -4
  25. package/templates/starter.js +2 -2
  26. package/types/data/CookieObject.d.ts +34 -0
  27. package/types/data/CookieObject.d.ts.map +1 -0
  28. package/types/data/custom-types.d.ts +111 -0
  29. package/types/data/custom-types.d.ts.map +1 -0
  30. package/types/errata/socketio.d.ts +11 -0
  31. package/types/errata/socketio.d.ts.map +1 -0
  32. package/types/examples/starter.d.ts +2 -0
  33. package/types/examples/starter.d.ts.map +1 -0
  34. package/types/helpers/HeadersParser.d.ts +27 -0
  35. package/types/helpers/HeadersParser.d.ts.map +1 -0
  36. package/types/helpers/HttpListener.d.ts +84 -0
  37. package/types/helpers/HttpListener.d.ts.map +1 -0
  38. package/types/helpers/RequestHeaders.d.ts +25 -0
  39. package/types/helpers/RequestHeaders.d.ts.map +1 -0
  40. package/types/helpers/RequestReader.d.ts +52 -0
  41. package/types/helpers/RequestReader.d.ts.map +1 -0
  42. package/types/helpers/ResponseHeaders.d.ts +126 -0
  43. package/types/helpers/ResponseHeaders.d.ts.map +1 -0
  44. package/types/helpers/index.d.ts +6 -0
  45. package/types/helpers/index.d.ts.map +1 -0
  46. package/types/lib/HttpHandler.d.ts +79 -0
  47. package/types/lib/HttpHandler.d.ts.map +1 -0
  48. package/types/lib/HttpRequest.d.ts +175 -0
  49. package/types/lib/HttpRequest.d.ts.map +1 -0
  50. package/types/lib/HttpResponse.d.ts +117 -0
  51. package/types/lib/HttpResponse.d.ts.map +1 -0
  52. package/types/lib/HttpTransaction.d.ts +114 -0
  53. package/types/lib/HttpTransaction.d.ts.map +1 -0
  54. package/types/middleware/AutoHeadersMiddleware.d.ts +27 -0
  55. package/types/middleware/AutoHeadersMiddleware.d.ts.map +1 -0
  56. package/types/middleware/CORSMiddleware.d.ts +65 -0
  57. package/types/middleware/CORSMiddleware.d.ts.map +1 -0
  58. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts +27 -0
  59. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts.map +1 -0
  60. package/types/middleware/ContentDecoderMiddleware.d.ts +17 -0
  61. package/types/middleware/ContentDecoderMiddleware.d.ts.map +1 -0
  62. package/types/middleware/ContentEncoderMiddleware.d.ts +48 -0
  63. package/types/middleware/ContentEncoderMiddleware.d.ts.map +1 -0
  64. package/types/middleware/ContentLengthMiddleware.d.ts +38 -0
  65. package/types/middleware/ContentLengthMiddleware.d.ts.map +1 -0
  66. package/types/middleware/HashMiddleware.d.ts +28 -0
  67. package/types/middleware/HashMiddleware.d.ts.map +1 -0
  68. package/types/middleware/HeadMethodMiddleware.d.ts +12 -0
  69. package/types/middleware/HeadMethodMiddleware.d.ts.map +1 -0
  70. package/types/middleware/MethodMiddleware.d.ts +40 -0
  71. package/types/middleware/MethodMiddleware.d.ts.map +1 -0
  72. package/types/middleware/PathMiddleware.d.ts +81 -0
  73. package/types/middleware/PathMiddleware.d.ts.map +1 -0
  74. package/types/middleware/ReadFormData.d.ts +7 -0
  75. package/types/middleware/ReadFormData.d.ts.map +1 -0
  76. package/types/middleware/SendJsonMiddleware.d.ts +51 -0
  77. package/types/middleware/SendJsonMiddleware.d.ts.map +1 -0
  78. package/types/middleware/SendStringMiddleware.d.ts +35 -0
  79. package/types/middleware/SendStringMiddleware.d.ts.map +1 -0
  80. package/types/templates/starter.d.ts +15 -0
  81. package/types/templates/starter.d.ts.map +1 -0
  82. package/types/utils/AsyncObject.d.ts +38 -0
  83. package/types/utils/AsyncObject.d.ts.map +1 -0
  84. package/types/utils/CaseInsensitiveObject.d.ts +9 -0
  85. package/types/utils/CaseInsensitiveObject.d.ts.map +1 -0
  86. package/types/utils/function.d.ts +2 -0
  87. package/types/utils/function.d.ts.map +1 -0
  88. package/types/utils/headers.d.ts +7 -0
  89. package/types/utils/headers.d.ts.map +1 -0
  90. package/types/utils/qualityValues.d.ts +12 -0
  91. package/types/utils/qualityValues.d.ts.map +1 -0
  92. package/types/utils/stream.d.ts +6 -0
  93. package/types/utils/stream.d.ts.map +1 -0
  94. package/utils/headers.js +1 -1
  95. package/.eslintrc.json +0 -96
  96. package/.github/FUNDING.yml +0 -4
  97. package/.github/copilot-instructions.md +0 -100
  98. package/.github/workflows/publish.yml +0 -29
  99. package/.github/workflows/test-matrix.yml +0 -37
  100. package/.test/benchmark.js +0 -28
  101. package/.test/constants.js +0 -4
  102. package/.test/cookietester.js +0 -19
  103. package/.test/http2server.js +0 -35
  104. package/.test/httpserver.js +0 -32
  105. package/.test/index.js +0 -498
  106. package/.test/multipromise.js +0 -32
  107. package/.test/tls.js +0 -75
  108. package/.test/urlencoded.js +0 -54
  109. package/.vscode/launch.json +0 -35
  110. package/.vscode/settings.json +0 -5
  111. package/CHANGELOG.md +0 -10
  112. package/CODE_OF_CONDUCT.md +0 -76
  113. package/errata/index.js +0 -1
  114. package/examples/starter.js +0 -11
  115. package/index.js +0 -4
  116. package/jsconfig.json +0 -12
  117. package/lib/index.js +0 -3
  118. package/middleware/ContentReaderMiddleware.js +0 -249
  119. package/middleware/ContentWriterMiddleware.js +0 -161
  120. package/middleware/SendHeadersMiddleware.js +0 -47
  121. package/middleware/index.js +0 -11
  122. package/polyfill/FormData.js +0 -164
  123. package/rollup.config.js +0 -8
  124. package/scripts/check-teapot.mjs +0 -40
  125. package/scripts/test-all-sync.sh +0 -6
  126. package/scripts/test-all.sh +0 -7
  127. package/test/fixtures/stream.js +0 -68
  128. package/test/helpers/HttpListener/construct.js +0 -18
  129. package/test/helpers/HttpListener/customOptions.js +0 -22
  130. package/test/helpers/HttpListener/doubleCreate.js +0 -40
  131. package/test/helpers/HttpListener/events.js +0 -77
  132. package/test/helpers/HttpListener/http.js +0 -31
  133. package/test/helpers/HttpListener/http2.js +0 -41
  134. package/test/helpers/HttpListener/https.js +0 -38
  135. package/test/helpers/HttpListener/startAll.js +0 -31
  136. package/test/helpers/HttpListener/stopNotStarted.js +0 -23
  137. package/test/lib/HttpHandler/class.js +0 -8
  138. package/test/lib/HttpHandler/handleRequest.js +0 -11
  139. package/test/lib/HttpHandler/middleware.js +0 -941
  140. package/test/lib/HttpHandler/parse.js +0 -41
  141. package/test/lib/HttpRequest/class.js +0 -8
  142. package/test/lib/HttpRequest/downstream.js +0 -171
  143. package/test/lib/HttpRequest/properties.js +0 -101
  144. package/test/lib/HttpRequest/read.js +0 -518
  145. package/test/lib/HttpResponse/async-iterable-middleware.js +0 -37
  146. package/test/lib/HttpResponse/async-iterable.js +0 -31
  147. package/test/lib/HttpResponse/class.js +0 -8
  148. package/test/lib/HttpResponse/properties.js +0 -59
  149. package/test/lib/HttpResponse/send.js +0 -275
  150. package/test/lib/HttpTransaction/class.js +0 -8
  151. package/test/lib/HttpTransaction/ping.js +0 -50
  152. package/test/lib/HttpTransaction/push.js +0 -89
  153. package/test/middleware/SendJsonMiddleware.js +0 -222
  154. package/test/sanity.js +0 -10
  155. package/test/templates/error-teapot.js +0 -47
  156. package/test/templates/starter.js +0 -93
  157. package/tsconfig.json +0 -30
@@ -1,41 +0,0 @@
1
- import test from 'ava';
2
-
3
- import HttpHandler from '../../../lib/HttpHandler.js';
4
-
5
- test('HttpHandler.ParseResultSync returns correct flow instructions', (t) => {
6
- t.is(HttpHandler.ParseResultSync(true), HttpHandler.CONTINUE);
7
- t.is(HttpHandler.ParseResultSync(null), HttpHandler.CONTINUE);
8
- t.is(HttpHandler.ParseResultSync(undefined), HttpHandler.CONTINUE);
9
- t.is(HttpHandler.ParseResultSync(HttpHandler.CONTINUE), HttpHandler.CONTINUE);
10
- t.is(HttpHandler.ParseResultSync(false), HttpHandler.BREAK);
11
- t.is(HttpHandler.ParseResultSync(HttpHandler.BREAK), HttpHandler.BREAK);
12
- t.is(HttpHandler.ParseResultSync(0), HttpHandler.END);
13
- t.is(HttpHandler.ParseResultSync(HttpHandler.END), HttpHandler.END);
14
- t.is(HttpHandler.ParseResultSync('other'), null);
15
- });
16
-
17
- test('HttpHandler.parseURL parses basic URL', (t) => {
18
- const url = HttpHandler.parseURL('http', 'localhost:8080', '/foo/bar?baz=1#frag');
19
- t.is(url.href, 'http://localhost:8080/foo/bar?baz=1#frag');
20
- t.is(url.origin, 'http://localhost:8080');
21
- t.is(url.protocol, 'http:');
22
- t.is(url.host, 'localhost:8080');
23
- t.is(url.hostname, 'localhost');
24
- t.is(url.port, '8080');
25
- t.is(url.pathname, '/foo/bar');
26
- t.is(url.search, '?baz=1');
27
- t.is(url.hash, '#frag');
28
- t.is(url.query, 'baz=1');
29
- t.is(url.fragment, 'frag');
30
- t.is(url.url, 'http://localhost:8080/foo/bar?baz=1#frag');
31
- });
32
-
33
- test('HttpHandler.parseURL parses URL with no query or fragment', (t) => {
34
- const url = HttpHandler.parseURL('https', 'example.com', '/path');
35
- t.is(url.href, 'https://example.com/path');
36
- t.is(url.pathname, '/path');
37
- t.is(url.search, '');
38
- t.is(url.hash, '');
39
- t.is(url.query, '');
40
- t.is(url.fragment, '');
41
- });
@@ -1,8 +0,0 @@
1
- import test from 'ava';
2
-
3
- import HttpRequest from '../../../lib/HttpRequest.js';
4
-
5
- test('new HttpRequest()', (t) => {
6
- const req = new HttpRequest({});
7
- t.assert(req instanceof HttpRequest);
8
- });
@@ -1,171 +0,0 @@
1
- import { PassThrough, Readable } from 'node:stream';
2
-
3
- import test from 'ava';
4
-
5
- import HttpRequest from '../../../lib/HttpRequest.js';
6
-
7
- test('HttpRequest.addDownstream() - notreadable', (t) => {
8
- const source = Readable.from(['foo']);
9
- const req = new HttpRequest({ stream: source });
10
- t.true(req.stream.readable);
11
- req.stream.destroy();
12
- t.false(req.stream.readable);
13
- const error = t.throws(() => req.addDownstream(new PassThrough()));
14
- t.assert(error.message, 'STREAM_NOT_READABLE');
15
- });
16
-
17
- test('HttpRequest.addDownstream() - forwardErrors optional', (t) => {
18
- const source = Readable.from(['foo']);
19
- const downstream = new PassThrough();
20
- const req = new HttpRequest({ stream: source });
21
- req.addDownstream(downstream);
22
- t.plan(2);
23
- source.addListener('error', (err) => {
24
- t.assert(err.message, 'TEST');
25
- });
26
- downstream.addListener('error', (err) => {
27
- t.assert(err.message, 'TEST');
28
- });
29
- downstream.emit('error', new Error('TEST'));
30
- });
31
-
32
- test('HttpRequest.addDownstream() - forwardErrors true', (t) => {
33
- const source = Readable.from(['foo']);
34
- const downstream = new PassThrough();
35
- const req = new HttpRequest({ stream: source });
36
- req.addDownstream(downstream, { forwardErrors: true });
37
- t.plan(2);
38
- source.addListener('error', (err) => {
39
- t.assert(err.message, 'TEST');
40
- });
41
- downstream.addListener('error', (err) => {
42
- t.assert(err.message, 'TEST');
43
- });
44
- downstream.emit('error', new Error('TEST'));
45
- });
46
-
47
- test('HttpRequest.addDownstream() - forwardErrors false', (t) => {
48
- const source = Readable.from(['foo']);
49
- const downstream = new PassThrough();
50
- const req = new HttpRequest({ stream: source });
51
- req.addDownstream(downstream, { forwardErrors: false });
52
- t.plan(1);
53
- source.addListener('error', (err) => {
54
- t.fail('Error should not have been called');
55
- });
56
- downstream.addListener('error', (err) => {
57
- t.assert(err.message, 'TEST');
58
- });
59
- downstream.emit('error', new Error('TEST'));
60
- });
61
-
62
- test('HttpRequest.addDownstream() - destroy on external consumption', async (t) => {
63
- const source = Readable.from(['foo']);
64
- const downstream = new PassThrough();
65
- const req = new HttpRequest({ stream: source });
66
- req.addDownstream(downstream, { autoPipe: false });
67
- t.true(source.readable);
68
- t.false(source.readableEnded);
69
-
70
- // Consume outside
71
- for await (const chunk of source) {
72
- t.is(chunk, 'foo');
73
- }
74
- t.false(source.readable);
75
- t.true(source.readableEnded);
76
-
77
- t.false(downstream.readable);
78
- });
79
-
80
- test('HttpRequest.addDownstream() - destroy on external destroy', async (t) => {
81
- const source = Readable.from(['foo']);
82
- const downstream = new PassThrough();
83
- const req = new HttpRequest({ stream: source });
84
- req.addDownstream(downstream, { autoPipe: false });
85
- t.true(source.readable);
86
-
87
- source.destroy();
88
- t.false(source.readable);
89
-
90
- // 'close' event only occurs on next cycle
91
- await new Promise((r) => setImmediate(r));
92
- t.false(downstream.readable);
93
- });
94
-
95
- test('HttpRequest.addDownstream() - autoPipe', async (t) => {
96
- const source = Readable.from(['foo']);
97
- const downstream = new PassThrough();
98
- const req = new HttpRequest({ stream: source });
99
-
100
- t.is(downstream.listenerCount('unpipe'), 0);
101
- req.addDownstream(downstream);
102
- t.is(downstream.listenerCount('unpipe'), 1);
103
-
104
- for await (const chunk of downstream) {
105
- t.is(chunk.toString(), 'foo');
106
- }
107
-
108
- t.false(source.readable);
109
- t.true(source.readableEnded);
110
-
111
- t.false(downstream.readable);
112
- t.true(downstream.readableEnded);
113
- });
114
-
115
- test('HttpRequest.addDownstream() - autoPipe true', async (t) => {
116
- const source = Readable.from(['foo']);
117
- const downstream = new PassThrough();
118
- const req = new HttpRequest({ stream: source });
119
-
120
- t.is(downstream.listenerCount('unpipe'), 0);
121
- req.addDownstream(downstream, { autoPipe: true });
122
- t.is(downstream.listenerCount('unpipe'), 1);
123
- });
124
-
125
- test('HttpRequest.addDownstream() - autoPipe false', async (t) => {
126
- const source = Readable.from(['foo']);
127
- const downstream = new PassThrough();
128
- const req = new HttpRequest({ stream: source });
129
-
130
- t.is(downstream.listenerCount('unpipe'), 0);
131
- req.addDownstream(downstream, { autoPipe: false });
132
- t.is(downstream.listenerCount('unpipe'), 0);
133
- });
134
-
135
- test('HttpRequest.addDownstream() - autoPause', async (t) => {
136
- const source = Readable.from(['foo']);
137
- const downstream = new PassThrough();
138
- const req = new HttpRequest({ stream: source });
139
-
140
- req.addDownstream(downstream);
141
- t.false(source.isPaused());
142
- });
143
-
144
- test('HttpRequest.addDownstream() - autoPause true', async (t) => {
145
- const source = Readable.from(['foo']);
146
- const downstream = new PassThrough();
147
- const req = new HttpRequest({ stream: source });
148
-
149
- req.addDownstream(downstream, { autoPause: true });
150
- t.true(source.isPaused());
151
- });
152
-
153
- test('HttpRequest.addDownstream() - autoPause false', async (t) => {
154
- const source = Readable.from(['foo']);
155
- const downstream = new PassThrough();
156
- const req = new HttpRequest({ stream: source });
157
-
158
- req.addDownstream(downstream, { autoPipe: false });
159
- t.false(source.isPaused());
160
- });
161
-
162
- test('HttpRequest.addDownstream() - string encoder text()', async (t) => {
163
- const text = 'foo';
164
- const source = Readable.from([Buffer.from(text)]);
165
- const downstream = new PassThrough();
166
- downstream.setEncoding('utf8');
167
- const req = new HttpRequest({ stream: source, headers: {} });
168
- req.addDownstream(downstream);
169
- const data = await req.text();
170
- t.is(data, text);
171
- });
@@ -1,101 +0,0 @@
1
- import test from 'ava';
2
-
3
- import HttpRequest from '../../../lib/HttpRequest.js';
4
-
5
- test('HttpRequest.URL', (t) => {
6
- const url = 'http://my.domain.name/pathname?foo=bar&baz=qux/#hash';
7
- const request = new HttpRequest({ url });
8
-
9
- t.is(url, request.url);
10
-
11
- const urlObject = new URL(request.url);
12
-
13
- t.assert(urlObject instanceof URL);
14
- t.is(url, urlObject.toString());
15
- });
16
-
17
- test('HttpRequest.mediaType', (t) => {
18
- /** @type {Record<string, Partial<import('../../../lib/HttpRequest.js').MediaType>>} */
19
- const entries = {
20
- 'text/html': { type: 'text', subtype: 'html' },
21
- 'application/ls+json': { type: 'application', subtype: 'ls', suffix: 'json' },
22
- 'application/vnd.ms-excel': { type: 'application', tree: 'vnd', subtype: 'ms-excel' },
23
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation': {
24
- type: 'application', tree: 'vnd.openxmlformats-officedocument.presentationml', subtype: 'presentation',
25
- },
26
- 'application/vnd.api+json': {
27
- type: 'application', tree: 'vnd', subtype: 'api', suffix: 'json',
28
- },
29
- 'application/vnd.api;charset=utf-8': {
30
- type: 'application', tree: 'vnd', subtype: 'api', parameters: { charset: 'utf-8' },
31
- },
32
- 'application/vnd.api+json;charset=utf-8': {
33
- type: 'application', tree: 'vnd', subtype: 'api', suffix: 'json', parameters: { charset: 'utf-8' },
34
- },
35
- 'multipart/mixed;boundary=gc0p4Jq0M2Yt08jU534c0p': {
36
- type: 'multipart', subtype: 'mixed', parameters: { boundary: 'gc0p4Jq0M2Yt08jU534c0p' },
37
- },
38
- 'multipart/mixed;boundary="spaced quotation"': {
39
- type: 'multipart', subtype: 'mixed', parameters: { boundary: 'spaced quotation' },
40
- },
41
- };
42
- for (const [contentType, entry] of Object.entries(entries)) {
43
- const request = new HttpRequest({ headers: { 'content-type': contentType } });
44
- for (const property of ['type', 'suffix', 'subtype']) {
45
- if (property in entry) {
46
- t.is(request.mediaType[property], entry[property]);
47
- } else {
48
- t.falsy(request.mediaType[property]);
49
- }
50
- }
51
- t.deepEqual(entry.parameters ?? {}, request.mediaType.parameters);
52
- }
53
- });
54
-
55
- test('HttpRequest.mediaType - error', (t) => {
56
- /** @type {Record<string, Partial<import('../../../lib/HttpRequest.js').MediaType>>} */
57
-
58
- const request = new HttpRequest({ headers: { 'content-type': 'multipart/mixed;boundary=improper"quotes' } });
59
- const error = t.throws(() => request.mediaType);
60
- t.is(error.message, 'ERR_CONTENT_TYPE');
61
- });
62
-
63
- test('HttpRequest.charset', (t) => {
64
- /** @type {Record<string, string>} */
65
- const entries = {
66
- 'text/html': null,
67
- 'application/ls+json': null,
68
- 'application/vnd.ms-excel': null,
69
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation': null,
70
- 'application/vnd.api+json': null,
71
- 'application/vnd.api;charset=utf-8': 'utf-8',
72
- 'application/vnd.api+json;charset=utf-8': 'utf-8',
73
- 'multipart/mixed;boundary=gc0p4Jq0M2Yt08jU534c0p': null,
74
- 'multipart/mixed;boundary=gc0p4Jq0M2Yt08jU534c0p;charset=ascii': 'ascii',
75
- };
76
- for (const [contentType, charset] of Object.entries(entries)) {
77
- const request = new HttpRequest({ headers: { 'content-type': contentType } });
78
- if (charset) {
79
- t.is(request.charset, charset);
80
- } else {
81
- t.falsy(request.charset);
82
- }
83
- }
84
- });
85
-
86
- test('HttpRequest.bufferEncoding', (t) => {
87
- /** @type {Record<string, BufferEncoding>} */
88
- const entries = {
89
- 'application/json': 'latin1',
90
- 'application/json;charset=ascii': 'latin1',
91
- 'application/json;charset=utf-8': 'utf-8',
92
- 'application/json;charset=ucs-2': 'utf16le',
93
- 'application/json;charset=utf8': 'utf-8',
94
- 'application/json;charset=hex': 'hex',
95
- 'application/json;charset=base64': 'base64',
96
- };
97
- for (const [contentType, bufferEncoding] of Object.entries(entries)) {
98
- const request = new HttpRequest({ headers: { 'content-type': contentType } });
99
- t.is(request.bufferEncoding, bufferEncoding);
100
- }
101
- });