webhoster 0.3.4 → 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 (125) hide show
  1. package/package.json +12 -1
  2. package/types/data/CookieObject.d.ts +34 -0
  3. package/types/data/CookieObject.d.ts.map +1 -0
  4. package/types/data/custom-types.d.ts +111 -0
  5. package/types/data/custom-types.d.ts.map +1 -0
  6. package/types/errata/socketio.d.ts +11 -0
  7. package/types/errata/socketio.d.ts.map +1 -0
  8. package/types/examples/starter.d.ts +2 -0
  9. package/types/examples/starter.d.ts.map +1 -0
  10. package/types/helpers/HeadersParser.d.ts +27 -0
  11. package/types/helpers/HeadersParser.d.ts.map +1 -0
  12. package/types/helpers/HttpListener.d.ts +84 -0
  13. package/types/helpers/HttpListener.d.ts.map +1 -0
  14. package/types/helpers/RequestHeaders.d.ts +25 -0
  15. package/types/helpers/RequestHeaders.d.ts.map +1 -0
  16. package/types/helpers/RequestReader.d.ts +52 -0
  17. package/types/helpers/RequestReader.d.ts.map +1 -0
  18. package/types/helpers/ResponseHeaders.d.ts +126 -0
  19. package/types/helpers/ResponseHeaders.d.ts.map +1 -0
  20. package/types/helpers/index.d.ts +6 -0
  21. package/types/helpers/index.d.ts.map +1 -0
  22. package/types/lib/HttpHandler.d.ts +79 -0
  23. package/types/lib/HttpHandler.d.ts.map +1 -0
  24. package/types/lib/HttpRequest.d.ts +175 -0
  25. package/types/lib/HttpRequest.d.ts.map +1 -0
  26. package/types/lib/HttpResponse.d.ts +117 -0
  27. package/types/lib/HttpResponse.d.ts.map +1 -0
  28. package/types/lib/HttpTransaction.d.ts +114 -0
  29. package/types/lib/HttpTransaction.d.ts.map +1 -0
  30. package/types/middleware/AutoHeadersMiddleware.d.ts +27 -0
  31. package/types/middleware/AutoHeadersMiddleware.d.ts.map +1 -0
  32. package/types/middleware/CORSMiddleware.d.ts +65 -0
  33. package/types/middleware/CORSMiddleware.d.ts.map +1 -0
  34. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts +27 -0
  35. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts.map +1 -0
  36. package/types/middleware/ContentDecoderMiddleware.d.ts +17 -0
  37. package/types/middleware/ContentDecoderMiddleware.d.ts.map +1 -0
  38. package/types/middleware/ContentEncoderMiddleware.d.ts +48 -0
  39. package/types/middleware/ContentEncoderMiddleware.d.ts.map +1 -0
  40. package/types/middleware/ContentLengthMiddleware.d.ts +38 -0
  41. package/types/middleware/ContentLengthMiddleware.d.ts.map +1 -0
  42. package/types/middleware/HashMiddleware.d.ts +28 -0
  43. package/types/middleware/HashMiddleware.d.ts.map +1 -0
  44. package/types/middleware/HeadMethodMiddleware.d.ts +12 -0
  45. package/types/middleware/HeadMethodMiddleware.d.ts.map +1 -0
  46. package/types/middleware/MethodMiddleware.d.ts +40 -0
  47. package/types/middleware/MethodMiddleware.d.ts.map +1 -0
  48. package/types/middleware/PathMiddleware.d.ts +81 -0
  49. package/types/middleware/PathMiddleware.d.ts.map +1 -0
  50. package/types/middleware/ReadFormData.d.ts +7 -0
  51. package/types/middleware/ReadFormData.d.ts.map +1 -0
  52. package/types/middleware/SendJsonMiddleware.d.ts +51 -0
  53. package/types/middleware/SendJsonMiddleware.d.ts.map +1 -0
  54. package/types/middleware/SendStringMiddleware.d.ts +35 -0
  55. package/types/middleware/SendStringMiddleware.d.ts.map +1 -0
  56. package/types/templates/starter.d.ts +15 -0
  57. package/types/templates/starter.d.ts.map +1 -0
  58. package/types/utils/AsyncObject.d.ts +38 -0
  59. package/types/utils/AsyncObject.d.ts.map +1 -0
  60. package/types/utils/CaseInsensitiveObject.d.ts +9 -0
  61. package/types/utils/CaseInsensitiveObject.d.ts.map +1 -0
  62. package/types/utils/function.d.ts +2 -0
  63. package/types/utils/function.d.ts.map +1 -0
  64. package/types/utils/headers.d.ts +7 -0
  65. package/types/utils/headers.d.ts.map +1 -0
  66. package/types/utils/qualityValues.d.ts +12 -0
  67. package/types/utils/qualityValues.d.ts.map +1 -0
  68. package/types/utils/stream.d.ts +6 -0
  69. package/types/utils/stream.d.ts.map +1 -0
  70. package/.eslintrc.json +0 -96
  71. package/.github/FUNDING.yml +0 -4
  72. package/.github/copilot-instructions.md +0 -100
  73. package/.github/workflows/publish.yml +0 -29
  74. package/.github/workflows/test-matrix.yml +0 -37
  75. package/.test/benchmark.js +0 -28
  76. package/.test/constants.js +0 -4
  77. package/.test/cookietester.js +0 -19
  78. package/.test/http2server.js +0 -35
  79. package/.test/httpserver.js +0 -32
  80. package/.test/index.js +0 -498
  81. package/.test/multipromise.js +0 -32
  82. package/.test/tls.js +0 -75
  83. package/.test/urlencoded.js +0 -54
  84. package/.vscode/launch.json +0 -35
  85. package/.vscode/settings.json +0 -5
  86. package/CHANGELOG.md +0 -10
  87. package/CODE_OF_CONDUCT.md +0 -76
  88. package/examples/starter.js +0 -11
  89. package/jsconfig.json +0 -12
  90. package/polyfill/FormData.js +0 -164
  91. package/rollup.config.js +0 -8
  92. package/scripts/check-teapot.mjs +0 -40
  93. package/scripts/test-all-sync.sh +0 -6
  94. package/scripts/test-all.sh +0 -7
  95. package/test/fixtures/stream.js +0 -68
  96. package/test/helpers/HttpListener/construct.js +0 -18
  97. package/test/helpers/HttpListener/customOptions.js +0 -22
  98. package/test/helpers/HttpListener/doubleCreate.js +0 -40
  99. package/test/helpers/HttpListener/events.js +0 -77
  100. package/test/helpers/HttpListener/http.js +0 -31
  101. package/test/helpers/HttpListener/http2.js +0 -41
  102. package/test/helpers/HttpListener/https.js +0 -38
  103. package/test/helpers/HttpListener/startAll.js +0 -31
  104. package/test/helpers/HttpListener/stopNotStarted.js +0 -23
  105. package/test/lib/HttpHandler/class.js +0 -8
  106. package/test/lib/HttpHandler/handleRequest.js +0 -11
  107. package/test/lib/HttpHandler/middleware.js +0 -941
  108. package/test/lib/HttpHandler/parse.js +0 -41
  109. package/test/lib/HttpRequest/class.js +0 -8
  110. package/test/lib/HttpRequest/downstream.js +0 -171
  111. package/test/lib/HttpRequest/properties.js +0 -101
  112. package/test/lib/HttpRequest/read.js +0 -518
  113. package/test/lib/HttpResponse/async-iterable-middleware.js +0 -37
  114. package/test/lib/HttpResponse/async-iterable.js +0 -31
  115. package/test/lib/HttpResponse/class.js +0 -8
  116. package/test/lib/HttpResponse/properties.js +0 -59
  117. package/test/lib/HttpResponse/send.js +0 -275
  118. package/test/lib/HttpTransaction/class.js +0 -8
  119. package/test/lib/HttpTransaction/ping.js +0 -50
  120. package/test/lib/HttpTransaction/push.js +0 -89
  121. package/test/middleware/SendJsonMiddleware.js +0 -222
  122. package/test/sanity.js +0 -10
  123. package/test/templates/error-teapot.js +0 -47
  124. package/test/templates/starter.js +0 -93
  125. package/tsconfig.json +0 -29
@@ -1,32 +0,0 @@
1
- const promises = [];
2
-
3
- async function waitAndLogPromise() {
4
- const p = (async() => {
5
- console.log('The promise is running');
6
- await new Promise((r) => setTimeout(r, 5000));
7
- console.log('The promise is completed');
8
- });
9
- let runningPromise = p();
10
- console.log('pushing p');
11
- promises.push(runningPromise);
12
- console.log('waiting for p');
13
- await runningPromise;
14
- }
15
-
16
- setTimeout(async () => {
17
- console.log('external pre. start');
18
- await Promise.all(promises);
19
- console.log('external pre. finished resolved');
20
- }, 100)
21
-
22
- setTimeout(async () => {
23
- console.log('external post. start');
24
- await Promise.all(promises);
25
- console.log('external post. finished resolved');
26
- }, 8000)
27
-
28
-
29
- console.log('waitAndLogPromise - start');
30
- await waitAndLogPromise();
31
- console.log('waitAndLogPromise - end');
32
-
package/.test/tls.js DELETED
@@ -1,75 +0,0 @@
1
- import { createSecureContext } from 'node:tls';
2
-
3
- import x509 from '@fidm/x509';
4
-
5
- /** @typedef {import('tls').SecureContext} SecureContext */
6
- /** @typedef {import('tls').TlsOptions} TlsOptions */
7
-
8
- /**
9
- * @callback SNICallback
10
- * @param {Error} err
11
- * @param {SecureContext} ctx
12
- * @return {void}
13
- */
14
-
15
- /** @type {Map<string, SecureContext>} */
16
- const contexts = new Map();
17
-
18
- /** @type {Map<string, TlsOptions>} */
19
- export const contextOptions = new Map();
20
-
21
- /**
22
- * @param {TlsOptions} defaultTlsOptions
23
- * @return {TlsOptions}
24
- */
25
- export function setup(defaultTlsOptions) {
26
- contextOptions.set('default', defaultTlsOptions);
27
- return defaultTlsOptions;
28
- }
29
-
30
- /**
31
- * @param {string} commonName
32
- * @param {string} serverName
33
- * @return {boolean}
34
- */
35
- function checkCommonName(commonName, serverName) {
36
- if (!commonName || !serverName) return false;
37
- return new RegExp(`^${commonName.replace('.', '\\.').replace('*', '.*')}$`, 'i').test(serverName);
38
- }
39
-
40
- /**
41
- * @param {string} servername
42
- * @param {SNICallback} cb
43
- * @return {void}
44
- */
45
- export function SNICallback(servername, cb) {
46
- const hasContext = contexts.has(servername);
47
- if (hasContext) {
48
- console.debug('Resuing context created for:', servername);
49
- cb(null, contexts.get(servername));
50
- return;
51
- }
52
- const options = [...contextOptions.values()].find((ctx) => {
53
- if (!ctx.cert) return false;
54
- const buffer = (typeof ctx.cert === 'string') ? Buffer.from(ctx.cert) : ctx.cert;
55
- const cert = x509.Certificate.fromPEM(buffer);
56
- // Check expired
57
- if (!cert.validTo || new Date() > cert.validTo) return false;
58
- // Check not ready
59
- if (!cert.validFrom || new Date() < cert.validFrom) return false;
60
- if (!cert || !cert.subject) return false;
61
- if (checkCommonName(cert.subject.commonName, servername)) return true;
62
- if (!cert.dnsNames) return false;
63
- return cert.dnsNames.some((/** @type {string} */ name) => checkCommonName(name, servername));
64
- });
65
- let context = null;
66
- if (options) {
67
- context = createSecureContext(options);
68
- console.debug('Context created for:', servername);
69
- } else {
70
- console.warn('Unknown servername:', servername);
71
- // Pick any?
72
- }
73
- contexts.set(servername, context);
74
- cb(null, context);
75
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * @param buffer
3
- */
4
- function decode(buffer) {
5
- const sequences = [];
6
- let startIndex = 0;
7
- for (let i = 0; i < buffer.length; i += 1) {
8
- if (buffer[i] === 0x26) {
9
- sequences.push(buffer.subarray(startIndex, i));
10
- startIndex = i + 1;
11
- }
12
- if (i === buffer.length - 1) {
13
- sequences.push(buffer.subarray(startIndex, i));
14
- }
15
- }
16
- console.log(buffer);
17
- console.log(sequences);
18
- /** @type {[string, string][]} */
19
- const output = [];
20
- sequences.forEach((bytes) => {
21
- if (!bytes.length) return;
22
-
23
- // Find 0x3D and replace 0x2B in one loop for better performance
24
- let indexOf0x3D = -1;
25
- for (let i = 0; i < bytes.length; i += 1) {
26
- switch (bytes[i]) {
27
- case 0x3D:
28
- if (indexOf0x3D === -1) {
29
- indexOf0x3D = i;
30
- }
31
- break;
32
- case 0x2B:
33
- bytes[i] = 0x20;
34
- break;
35
- default:
36
- }
37
- }
38
- let name;
39
- let value;
40
- if (indexOf0x3D === -1) {
41
- name = bytes;
42
- value = bytes.subarray(bytes.length, 0);
43
- } else {
44
- name = bytes.subarray(0, indexOf0x3D);
45
- value = bytes.subarray(indexOf0x3D + 1);
46
- }
47
- const nameString = decodeURIComponent(name.toString('utf-8'));
48
- const valueString = decodeURIComponent(value.toString('utf-8'));
49
- output.push([nameString, valueString]);
50
- });
51
- return output;
52
- }
53
-
54
- console.log(decode(Buffer.from('field1=Ƣvalue1&field2=value2&&&=&==')));
@@ -1,35 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "Debug AVA",
9
- "request": "launch",
10
- "runtimeArgs": [
11
- "run-script",
12
- "debug-test"
13
- ],
14
- "runtimeExecutable": "npm",
15
- "skipFiles": [
16
- "<node_internals>/**"
17
- ],
18
- "type": "pwa-node"
19
- },
20
- {
21
- "type": "node",
22
- "request": "launch",
23
- "name": "Debug AVA test file",
24
- "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
25
- "runtimeArgs": [
26
- "--serial",
27
- "${file}"
28
- ],
29
- "outputCapture": "std",
30
- "skipFiles": [
31
- "<node_internals>/**/*.js"
32
- ]
33
- },
34
- ]
35
- }
@@ -1,5 +0,0 @@
1
- {
2
- "javascript.preferences.importModuleSpecifier": "relative",
3
- "javascript.preferences.importModuleSpecifierEnding": "js",
4
- "javascript.preferences.quoteStyle": "single"
5
- }
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- ## v0.0.5
2
- * Fix SocketIO errata
3
-
4
- ## v0.0.4
5
- * Add CommonJS support
6
- * Add `HttpListener` helper
7
- * Add SocketIO errata
8
-
9
- ## v0.0.3
10
- * Rename RequestHandler to HttpHandler
@@ -1,76 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, sex characteristics, gender identity and expression,
9
- level of experience, education, socio-economic status, nationality, personal
10
- appearance, race, religion, or sexual identity and orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at clshortfuse@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
-
73
- [homepage]: https://www.contributor-covenant.org
74
-
75
- For answers to common questions about this code of conduct, see
76
- https://www.contributor-covenant.org/faq
@@ -1,11 +0,0 @@
1
- import * as starter from '../templates/starter.js';
2
-
3
- const middleware = [
4
- () => 'Hello world!',
5
- ];
6
-
7
- // Start the singleton HTTP server using the starter convenience API.
8
- await starter.start({ middleware });
9
-
10
- // Export nothing — this example file is intended as a tiny runnable demo.
11
- export {};
package/jsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "checkJs": true,
4
- "noImplicitAny": true,
5
- "target": "es2022",
6
- "module": "esnext",
7
- "moduleResolution": "node"
8
- },
9
- "exclude": [
10
- "**/node_modules/*"
11
- ]
12
- }
@@ -1,164 +0,0 @@
1
- /* @see https://xhr.spec.whatwg.org/#dom-formdata */
2
-
3
- /** @implements {FormData} */
4
- export default class FormData {
5
- /** @type {Map<string, (string|File)[]>} */
6
- #list = new Map();
7
-
8
- /** @param {HTMLFormElement} [form] */
9
- constructor(form) {
10
- if (form) {
11
- throw new Error('InvalidStateError');
12
- }
13
- }
14
-
15
- /**
16
- * @param {string} s
17
- * @return {string}
18
- */
19
- static #scalarValue = String;
20
-
21
- /**
22
- * @param {string} name
23
- * @param {string|Blob} value
24
- * @param {string} [filename]
25
- * @return {{name:string, value:string|File}}
26
- */
27
- static #createEntry(name, value, filename) {
28
- if (typeof value === 'string') {
29
- return {
30
- name: FormData.#scalarValue(name),
31
- value: FormData.#scalarValue(value),
32
- };
33
- }
34
-
35
- if (typeof File === 'undefined') {
36
- if (!('name' in value) && !('lastModified' in value)) {
37
- /** @type {File} */
38
- // eslint-disable-next-line unicorn/prefer-spread
39
- const file = Object.defineProperties(value.slice(), {
40
- name: {
41
- value: filename === undefined ? 'blob' : filename,
42
- },
43
- lastModified: {
44
- value: Date.now(),
45
- },
46
- toString: { value: () => '[object File]' },
47
- });
48
- return {
49
- name: FormData.#scalarValue(name),
50
- value: file,
51
- };
52
- }
53
- return {
54
- name: FormData.#scalarValue(name),
55
- value,
56
- };
57
- }
58
- if (value instanceof File) {
59
- return {
60
- name: FormData.#scalarValue(name),
61
- value,
62
- };
63
- }
64
- return {
65
- name: FormData.#scalarValue(name),
66
- value: new File([value], filename === undefined ? 'blob' : filename, {}),
67
- };
68
- }
69
-
70
- /**
71
- * @param {string} name
72
- * @param {string|Blob} value
73
- * @param {string} [filename]
74
- * @return {void}
75
- */
76
- append(name, value, filename) {
77
- const entry = FormData.#createEntry(name, value, filename);
78
- console.log(entry);
79
- if (this.#list.has(entry.name)) {
80
- this.#list.get(entry.name).push(entry.value);
81
- } else {
82
- this.#list.set(name, [entry.value]);
83
- }
84
- }
85
-
86
- /**
87
- * @param {string} name
88
- * @return {void}
89
- */
90
- delete(name) {
91
- this.#list.delete(name);
92
- }
93
-
94
- /**
95
- * @param {string} name
96
- * @return {null|File|string}
97
- */
98
- get(name) {
99
- const entry = this.#list.get(name);
100
- if (!entry) return null;
101
- return entry[0];
102
- }
103
-
104
- /**
105
- * @param {string} name
106
- * @return {(File|string)[]}
107
- */
108
- getAll(name) {
109
- return this.#list.get(name) ?? [];
110
- }
111
-
112
- /**
113
- * @param {string} name
114
- * @return {boolean}
115
- */
116
- has(name) {
117
- return this.#list.has(name);
118
- }
119
-
120
- /**
121
- * @param {string} name
122
- * @param {string|Blob} value
123
- * @param {string} [filename]
124
- * @return {void}
125
- */
126
- set(name, value, filename) {
127
- const entry = FormData.#createEntry(name, value, filename);
128
- if (this.#list.has(entry.name)) {
129
- const entries = this.#list.get(name);
130
- entries.splice(0, entries.length, entry.value);
131
- } else {
132
- this.#list.set(name, [entry.value]);
133
- }
134
- }
135
-
136
- /**
137
- * @param {(value:(string|File), key:string, parent:this) => void} callback
138
- * @return {void}
139
- */
140
- forEach(callback) {
141
- for (const [key, value] of this) {
142
- callback(value, key, this);
143
- }
144
- }
145
-
146
- get keys() {
147
- return this.#list.keys;
148
- }
149
-
150
- * values() {
151
- for (const value of this.#list.values()) {
152
- yield value[0];
153
- }
154
- }
155
-
156
- * [Symbol.iterator]() {
157
- for (const entry of this.#list.entries()) {
158
- yield /** @type {[string, string|File]} */ ([entry[0], entry[1][0]]);
159
- }
160
- }
161
- }
162
-
163
- FormData.prototype.entries = FormData.prototype[Symbol.iterator];
164
- FormData.prototype.toString = () => '[Object FormData]';
package/rollup.config.js DELETED
@@ -1,8 +0,0 @@
1
- /** @typedef {import('rollup')} */
2
- export default {
3
- input: 'index.js',
4
- output: {
5
- file: 'index.cjs',
6
- format: 'cjs',
7
- },
8
- };
@@ -1,40 +0,0 @@
1
- import http from 'node:http';
2
- import * as starter from '../templates/starter.js';
3
-
4
- async function run() {
5
- const throwingMiddleware = [() => { throw new Error('brew failed'); }];
6
- const teapotHandler = {
7
- onError(transaction) {
8
- transaction.response.status = 418;
9
- return "I'm a teapot";
10
- },
11
- };
12
-
13
- const listener = await starter.start({ middleware: throwingMiddleware, errorHandlers: [teapotHandler], host: '127.0.0.1', port: 0 });
14
- try {
15
- const addr = listener.httpServer.address();
16
- const port = typeof addr === 'object' ? addr.port : addr;
17
- const result = await new Promise((resolve, reject) => {
18
- const req = http.get({ port, path: '/' }, (res) => {
19
- let data = '';
20
- res.setEncoding('utf8');
21
- res.on('data', (c) => { data += c; });
22
- res.on('end', () => resolve({ status: res.statusCode, body: data }));
23
- });
24
- req.on('error', reject);
25
- });
26
-
27
- // Print a concise confirmation
28
- // (CI will show this output in the terminal)
29
- // eslint-disable-next-line no-console
30
- console.log('TEAPOT_CHECK_RESULT', JSON.stringify(result));
31
- } finally {
32
- await listener.stopHttpServer();
33
- }
34
- }
35
-
36
- run().catch((err) => {
37
- // eslint-disable-next-line no-console
38
- console.error('check-teapot failed', err);
39
- process.exit(1);
40
- });
@@ -1,6 +0,0 @@
1
- . ~/.nvm/nvm.sh;
2
- nvm install 16.13; nvm use 16.13; npx c8 --clean false -r none ava;
3
- nvm install 16 ; nvm use 16 ; npx c8 --clean false -r none ava;
4
- nvm install 18 ; nvm use 18 ; npx c8 --clean false -r none ava;
5
- nvm install 20 ; nvm use 20 ; npx c8 --clean false -r none ava;
6
- nvm install 22 ; nvm use 22 ; npx c8 --clean false -r none ava;
@@ -1,7 +0,0 @@
1
- echo . \
2
- & sh -c ". ~/.nvm/nvm.sh; nvm install 16.13; nvm use 16.13; npx c8 --clean false -r none ava;" \
3
- & sh -c ". ~/.nvm/nvm.sh; nvm install 16; nvm use 16; npx c8 --clean false -r none ava;" \
4
- & sh -c ". ~/.nvm/nvm.sh; nvm install 18; nvm use 18; npx c8 --clean false -r none ava;" \
5
- & sh -c ". ~/.nvm/nvm.sh; nvm install 20; nvm use 20; npx c8 --clean false -r none ava;" \
6
- & sh -c ". ~/.nvm/nvm.sh; nvm install 22; nvm use 22; npx c8 --clean false -r none ava;" \
7
-
@@ -1,68 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import {
3
- Readable, pipeline as legacyPipeline,
4
- } from 'node:stream';
5
- import { promisify } from 'node:util';
6
-
7
- /** @type {import('node:stream/promises').pipeline} */
8
- let pipeline;
9
- try {
10
- ({ pipeline } = (await import('node:stream/promises')));
11
- } catch {
12
- pipeline = promisify(legacyPipeline);
13
- }
14
-
15
- const BUFFER_SIZE = 1024 * 16;
16
- const CHUNK_SIZE = 256 / 8;
17
- const CHUNK_COUNT = BUFFER_SIZE / CHUNK_SIZE;
18
-
19
- const SEED = Math.floor(Math.random() * (2 ** 4));
20
-
21
- /** @yields {Buffer} */
22
- function* binaryGenerator() {
23
- for (let index = 0; index < CHUNK_COUNT; index++) {
24
- const number_ = (SEED + index);
25
- /* eslint-disable no-bitwise */
26
- yield createHash('sha256').update(Buffer.from([
27
- (number_ >> 24) & 255,
28
- (number_ >> 16) & 255,
29
- (number_ >> 8) & 255,
30
- number_ & 255,
31
- ])).digest();
32
- /* eslint-enable no-bitwise */
33
- }
34
- }
35
-
36
- /** @yields {Buffer} */
37
- function* textGenerator() {
38
- for (const chunk of binaryGenerator()) {
39
- const hexString = chunk.toString('hex');
40
- yield Buffer.from(hexString, 'utf-8');
41
- }
42
- }
43
-
44
- /** @return {Readable} */
45
- export function getTestBinaryStream() {
46
- return Readable.from(binaryGenerator());
47
- }
48
-
49
- /** @return {Readable} */
50
- export function getTestTextStream() {
51
- return Readable.from(textGenerator());
52
- }
53
-
54
- /** @return {Promise<string>} */
55
- export async function getTestHash() {
56
- const hash = createHash('sha256');
57
- await pipeline(binaryGenerator(), hash);
58
- return hash.digest().toString('hex');
59
- }
60
-
61
- /** @return {string} */
62
- export function getTestString() {
63
- let data = '';
64
- for (const chunk of textGenerator()) {
65
- data += chunk;
66
- }
67
- return data;
68
- }
@@ -1,18 +0,0 @@
1
- import test from 'ava';
2
-
3
- import HttpListener from '../../../helpers/HttpListener.js';
4
-
5
- test('HttpListener can be constructed with defaults', (t) => {
6
- const listener = new HttpListener();
7
- t.truthy(listener);
8
- t.is(typeof listener.startHttpServer, 'function');
9
- t.is(typeof listener.stopHttpServer, 'function');
10
- });
11
-
12
- test('HttpListener.defaultInstance returns a singleton', (t) => {
13
- const inst1 = HttpListener.defaultInstance;
14
- const inst2 = HttpListener.defaultInstance;
15
- t.truthy(inst1);
16
- t.is(inst1, inst2);
17
- t.true(inst1 instanceof HttpListener);
18
- });
@@ -1,22 +0,0 @@
1
- import test from 'ava';
2
- import HttpListener from '../../../helpers/HttpListener.js';
3
-
4
- // Test custom port/host and handler injection
5
-
6
- test('custom insecurePort and insecureHost are set', t => {
7
- const listener = new HttpListener({ insecurePort: 1234, insecureHost: '127.0.0.1' });
8
- t.is(listener.insecurePort, 1234);
9
- t.is(listener.insecureHost, '127.0.0.1');
10
- });
11
-
12
- test('custom securePort and secureHost are set', t => {
13
- const listener = new HttpListener({ securePort: 4321, secureHost: 'localhost' });
14
- t.is(listener.securePort, 4321);
15
- t.is(listener.secureHost, 'localhost');
16
- });
17
-
18
- test('custom httpHandler is set', t => {
19
- const fakeHandler = { handleHttp1Request() {}, handleHttp2Stream() {} };
20
- const listener = new HttpListener({ httpHandler: fakeHandler });
21
- t.is(listener.httpHandler, fakeHandler);
22
- });