cf-workers-native 0.1.4 → 0.1.6
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/README.md +2 -2
- package/dist/browser/documents/page-source.js +1 -1
- package/dist/browser/fetch/host-call.js +6 -1
- package/dist/browser/fetch/native-network.d.ts +1 -1
- package/dist/browser/fetch/relay.js +2 -0
- package/dist/browser/headers/index.d.ts +2 -0
- package/dist/browser/headers/index.js +5 -0
- package/dist/browser/isolated/transport.js +3 -2
- package/dist/browser/request/index.js +3 -2
- package/dist/browser/response/index.d.ts +2 -0
- package/dist/browser/response/index.js +11 -3
- package/dist/browser/structured-clone/index.d.ts +3 -0
- package/dist/browser/structured-clone/index.js +75 -7
- package/dist/browser/websocket/attachment-size.d.ts +3 -0
- package/dist/browser/websocket/attachment-size.js +336 -0
- package/dist/browser/websocket/brand.d.ts +4 -0
- package/dist/browser/websocket/brand.js +16 -0
- package/dist/browser/websocket/close-event.d.ts +7 -0
- package/dist/browser/websocket/close-event.js +30 -0
- package/dist/browser/websocket/compression.d.ts +5 -0
- package/dist/browser/websocket/compression.js +124 -0
- package/dist/browser/websocket/conversion.d.ts +2 -0
- package/dist/browser/websocket/conversion.js +13 -0
- package/dist/browser/websocket/endpoint.d.ts +39 -0
- package/dist/browser/websocket/endpoint.js +379 -0
- package/dist/browser/websocket/frames.d.ts +21 -0
- package/dist/browser/websocket/frames.js +121 -0
- package/dist/browser/websocket/native.d.ts +14 -0
- package/dist/browser/websocket/native.js +226 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +11 -23
- package/dist/cloudflare/workers/worker-runtime.js +2 -1
- package/dist/compat/console/index.d.ts +35 -0
- package/dist/compat/console/index.js +92 -0
- package/dist/compat/crypto/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/crypto/LICENSE-APACHE +177 -0
- package/dist/compat/crypto/LICENSE.boringssl +238 -0
- package/dist/compat/crypto/LICENSE.emscripten +102 -0
- package/dist/compat/crypto/LICENSE.musl +193 -0
- package/dist/compat/crypto/LICENSE.ncrypto +21 -0
- package/dist/compat/crypto/LICENSE.openssl +177 -0
- package/dist/compat/crypto/asymmetric.d.ts +13 -0
- package/dist/compat/crypto/asymmetric.js +312 -0
- package/dist/compat/crypto/brorand.cjs +74 -0
- package/dist/compat/crypto/brorand.d.cts +6 -0
- package/dist/compat/crypto/certificate.d.ts +14 -0
- package/dist/compat/crypto/certificate.js +66 -0
- package/dist/compat/crypto/cipher-handle.d.ts +27 -0
- package/dist/compat/crypto/cipher-handle.js +239 -0
- package/dist/compat/crypto/cipher-info.d.ts +12 -0
- package/dist/compat/crypto/cipher-info.js +324 -0
- package/dist/compat/crypto/constants.d.ts +62 -0
- package/dist/compat/crypto/constants.js +68 -0
- package/dist/compat/crypto/dh-handle.d.ts +17 -0
- package/dist/compat/crypto/dh-handle.js +180 -0
- package/dist/compat/crypto/dh.d.ts +53 -0
- package/dist/compat/crypto/dh.js +138 -0
- package/dist/compat/crypto/digest-stream.d.ts +15 -0
- package/dist/compat/crypto/digest-stream.js +213 -0
- package/dist/compat/crypto/digests.d.ts +3 -0
- package/dist/compat/crypto/digests.js +32 -0
- package/dist/compat/crypto/ecdh.d.ts +25 -0
- package/dist/compat/crypto/ecdh.js +109 -0
- package/dist/compat/crypto/hash-handle.d.ts +23 -0
- package/dist/compat/crypto/hash-handle.js +70 -0
- package/dist/compat/crypto/hash.d.ts +37 -0
- package/dist/compat/crypto/hash.js +218 -0
- package/dist/compat/crypto/hkdf.d.ts +2 -0
- package/dist/compat/crypto/hkdf.js +78 -0
- package/dist/compat/crypto/index.cjs +2 -0
- package/dist/compat/crypto/index.d.cts +169 -0
- package/dist/compat/crypto/index.d.ts +213 -0
- package/dist/compat/crypto/index.js +96 -0
- package/dist/compat/crypto/key-errors.d.ts +10 -0
- package/dist/compat/crypto/key-errors.js +17 -0
- package/dist/compat/crypto/key-export.d.ts +8 -0
- package/dist/compat/crypto/key-export.js +49 -0
- package/dist/compat/crypto/key-formats.d.ts +7 -0
- package/dist/compat/crypto/key-formats.js +251 -0
- package/dist/compat/crypto/key-options.d.ts +1 -0
- package/dist/compat/crypto/key-options.js +74 -0
- package/dist/compat/crypto/key-state.d.ts +10 -0
- package/dist/compat/crypto/key-state.js +4 -0
- package/dist/compat/crypto/keys.d.ts +58 -0
- package/dist/compat/crypto/keys.js +278 -0
- package/dist/compat/crypto/metadata.d.ts +13 -0
- package/dist/compat/crypto/metadata.js +109 -0
- package/dist/compat/crypto/native-cipher.d.ts +17 -0
- package/dist/compat/crypto/native-cipher.js +192 -0
- package/dist/compat/crypto/native-crypto.d.ts +81 -0
- package/dist/compat/crypto/native-crypto.js +681 -0
- package/dist/compat/crypto/pbkdf2-handle.d.ts +4 -0
- package/dist/compat/crypto/pbkdf2-handle.js +26 -0
- package/dist/compat/crypto/pbkdf2.d.ts +5 -0
- package/dist/compat/crypto/pbkdf2.js +60 -0
- package/dist/compat/crypto/prime.d.ts +19 -0
- package/dist/compat/crypto/prime.js +146 -0
- package/dist/compat/crypto/random.d.ts +18 -0
- package/dist/compat/crypto/random.js +203 -0
- package/dist/compat/crypto/rsa.d.ts +21 -0
- package/dist/compat/crypto/rsa.js +177 -0
- package/dist/compat/crypto/scrypt.d.ts +25 -0
- package/dist/compat/crypto/scrypt.js +152 -0
- package/dist/compat/crypto/sign-errors.d.ts +8 -0
- package/dist/compat/crypto/sign-errors.js +13 -0
- package/dist/compat/crypto/sign-handle.d.ts +22 -0
- package/dist/compat/crypto/sign-handle.js +149 -0
- package/dist/compat/crypto/signatures.d.ts +34 -0
- package/dist/compat/crypto/signatures.js +252 -0
- package/dist/compat/crypto/subtle-digest.d.ts +1 -0
- package/dist/compat/crypto/subtle-digest.js +56 -0
- package/dist/compat/crypto/symmetric.d.ts +45 -0
- package/dist/compat/crypto/symmetric.js +239 -0
- package/dist/compat/crypto/validation.d.ts +7 -0
- package/dist/compat/crypto/validation.js +46 -0
- package/dist/compat/crypto/webcrypto.d.ts +13 -0
- package/dist/compat/crypto/webcrypto.js +51 -0
- package/dist/compat/crypto/x509.d.ts +30 -0
- package/dist/compat/crypto/x509.js +407 -0
- package/dist/compat/events/errors.d.ts +8 -0
- package/dist/compat/events/errors.js +39 -0
- package/dist/compat/events/index.cjs +2 -0
- package/dist/compat/events/index.d.cts +2 -0
- package/dist/compat/events/index.d.ts +64 -0
- package/dist/compat/events/index.js +792 -0
- package/dist/compat/events/intrinsics.d.ts +1 -0
- package/dist/compat/events/intrinsics.js +2 -0
- package/dist/compat/fs/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/fs/LICENSE-APACHE +177 -0
- package/dist/compat/fs/directory-backend.d.ts +6 -0
- package/dist/compat/fs/directory-backend.js +51 -0
- package/dist/compat/fs/directory.d.ts +37 -0
- package/dist/compat/fs/directory.js +137 -0
- package/dist/compat/fs/embedded.d.ts +85 -0
- package/dist/compat/fs/embedded.js +260 -0
- package/dist/compat/fs/file-handle.d.ts +75 -0
- package/dist/compat/fs/file-handle.js +226 -0
- package/dist/compat/fs/glob-internal.d.ts +15 -0
- package/dist/compat/fs/glob-internal.js +417 -0
- package/dist/compat/fs/glob.d.ts +10 -0
- package/dist/compat/fs/glob.js +71 -0
- package/dist/compat/fs/index.d.ts +8 -82
- package/dist/compat/fs/index.js +736 -238
- package/dist/compat/fs/io-validation.d.ts +14 -0
- package/dist/compat/fs/io-validation.js +130 -0
- package/dist/compat/fs/io.d.ts +1 -0
- package/dist/compat/fs/io.js +282 -0
- package/dist/compat/fs/mode.d.ts +1 -0
- package/dist/compat/fs/mode.js +13 -0
- package/dist/compat/fs/promises/index.d.ts +3 -1
- package/dist/compat/fs/promises/index.js +1 -1
- package/dist/compat/fs/public-types.d.ts +120 -0
- package/dist/compat/fs/public-types.js +1 -0
- package/dist/compat/fs/stream-errors.d.ts +6 -0
- package/dist/compat/fs/stream-errors.js +8 -0
- package/dist/compat/fs/stream-utils.d.ts +16 -0
- package/dist/compat/fs/stream-utils.js +29 -0
- package/dist/compat/fs/streams.d.ts +104 -0
- package/dist/compat/fs/streams.js +794 -0
- package/dist/compat/fs/writable.d.ts +14 -0
- package/dist/compat/fs/writable.js +532 -0
- package/dist/compat/http/index.d.ts +11 -28
- package/dist/compat/http/index.js +81 -125
- package/dist/compat/http/server-options.d.ts +1 -0
- package/dist/compat/http/server-options.js +87 -0
- package/dist/compat/http/symbols.d.ts +5 -0
- package/dist/compat/http/symbols.js +9 -0
- package/dist/compat/http/unique-headers.d.ts +1 -0
- package/dist/compat/http/unique-headers.js +21 -0
- package/dist/compat/http-common/index.d.ts +37 -0
- package/dist/compat/http-common/index.js +43 -0
- package/dist/compat/http-outgoing/index.d.ts +14 -0
- package/dist/compat/http-outgoing/index.js +17 -0
- package/dist/compat/http-server/index.d.ts +18 -0
- package/dist/compat/http-server/index.js +26 -0
- package/dist/compat/https/index.d.ts +4 -2
- package/dist/compat/module/builtins.d.ts +1 -0
- package/dist/compat/module/builtins.js +101 -0
- package/dist/compat/module/index.d.ts +4 -2
- package/dist/compat/module/index.js +22 -17
- package/dist/compat/module/metadata.d.ts +44 -0
- package/dist/compat/module/metadata.js +127 -0
- package/dist/compat/net/internal-net.js +4 -0
- package/dist/compat/net/sockets.d.ts +5 -0
- package/dist/compat/net/sockets.js +153 -14
- package/dist/compat/net/validators.d.ts +1 -0
- package/dist/compat/net/validators.js +8 -0
- package/dist/compat/process/configuration.d.ts +113 -0
- package/dist/compat/process/configuration.js +115 -0
- package/dist/compat/process/directory.d.ts +4 -0
- package/dist/compat/process/directory.js +28 -0
- package/dist/compat/process/files.d.ts +3 -0
- package/dist/compat/process/files.js +10 -0
- package/dist/compat/process/index.cjs +2 -0
- package/dist/compat/process/index.d.cts +4 -0
- package/dist/compat/process/index.d.ts +20 -0
- package/dist/compat/process/index.js +113 -0
- package/dist/compat/process/metadata.d.ts +135 -0
- package/dist/compat/process/metadata.js +251 -0
- package/dist/compat/process/scheduling.d.ts +2 -0
- package/dist/compat/process/scheduling.js +60 -0
- package/dist/compat/process/state.d.ts +4 -0
- package/dist/compat/process/state.js +5 -0
- package/dist/compat/process/stdio.d.ts +18 -0
- package/dist/compat/process/stdio.js +66 -0
- package/dist/compat/stream/destroy.d.ts +1 -0
- package/dist/compat/stream/destroy.js +21 -1
- package/dist/compat/stream/readable.js +10 -2
- package/dist/compat/stream-web/LICENSE +22 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -1
- package/dist/compat/stream-web/ponyfill.js +2369 -1775
- package/dist/compat/stream-web/runtime.d.ts +1 -1
- package/dist/compat/stream-web/runtime.js +3 -2
- package/dist/compat/stream-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/stream-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/stream-wrap/index.d.ts +1 -0
- package/dist/compat/stream-wrap/index.js +1 -0
- package/dist/compat/tls/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls/LICENSE-APACHE +177 -0
- package/dist/compat/tls/constants.d.ts +7 -0
- package/dist/compat/tls/constants.js +14 -0
- package/dist/compat/tls/errors.d.ts +35 -0
- package/dist/compat/tls/errors.js +68 -0
- package/dist/compat/tls/helpers.d.ts +9 -0
- package/dist/compat/tls/helpers.js +207 -0
- package/dist/compat/tls/index.d.ts +26 -0
- package/dist/compat/tls/index.js +50 -0
- package/dist/compat/tls/jsstream.d.ts +19 -0
- package/dist/compat/tls/jsstream.js +196 -0
- package/dist/compat/tls/native-session.d.ts +3 -0
- package/dist/compat/tls/native-session.js +187 -0
- package/dist/compat/tls/wrap.d.ts +65 -0
- package/dist/compat/tls/wrap.js +541 -0
- package/dist/compat/tls-wrap/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-wrap/LICENSE-APACHE +177 -0
- package/dist/compat/tls-wrap/index.d.ts +7 -0
- package/dist/compat/tls-wrap/index.js +3 -0
- package/dist/compat/util/index.js +43 -1
- package/dist/compat/util/inspect.js +5 -1
- package/dist/compat/util/types/index.d.ts +3 -0
- package/dist/compat/util/types/index.js +5 -0
- package/dist/compat/zlib/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/zlib/LICENSE-APACHE +177 -0
- package/dist/compat/zlib/LICENSE.brotli +19 -0
- package/dist/compat/zlib/LICENSE.emscripten +102 -0
- package/dist/compat/zlib/LICENSE.musl +193 -0
- package/dist/compat/zlib/LICENSE.zlib +22 -0
- package/dist/compat/zlib/LICENSE.zstd +30 -0
- package/dist/compat/zlib/classic-base.cjs +600 -0
- package/dist/compat/zlib/classic-base.d.cts +39 -0
- package/dist/compat/zlib/classic-binding.d.ts +28 -0
- package/dist/compat/zlib/classic-binding.js +105 -0
- package/dist/compat/zlib/classic.d.ts +44 -0
- package/dist/compat/zlib/classic.js +199 -0
- package/dist/compat/zlib/codec-binding.d.ts +33 -0
- package/dist/compat/zlib/codec-binding.js +141 -0
- package/dist/compat/zlib/compression.d.ts +26 -0
- package/dist/compat/zlib/compression.js +170 -0
- package/dist/compat/zlib/constants.d.ts +172 -0
- package/dist/compat/zlib/constants.js +173 -0
- package/dist/compat/zlib/errors.d.ts +21 -0
- package/dist/compat/zlib/errors.js +32 -0
- package/dist/compat/zlib/index.d.ts +544 -0
- package/dist/compat/zlib/index.js +194 -0
- package/dist/compat/zlib/input.d.ts +16 -0
- package/dist/compat/zlib/input.js +132 -0
- package/dist/compat/zlib/native-codecs.d.ts +24 -0
- package/dist/compat/zlib/native-codecs.js +180 -0
- package/dist/compat/zlib/native-zlib.d.ts +5 -0
- package/dist/compat/zlib/native-zlib.js +52 -0
- package/dist/compat/zlib/public-types.d.ts +48 -0
- package/dist/compat/zlib/public-types.js +1 -0
- package/dist/compat/zlib/validators.d.ts +3 -0
- package/dist/compat/zlib/validators.js +18 -0
- package/dist/shared/buffer-source.d.ts +5 -0
- package/dist/shared/buffer-source.js +70 -0
- package/dist/shared/globals/inject.d.ts +2 -1
- package/dist/shared/globals/inject.js +2 -1
- package/dist/shared/globals/platform.d.ts +8 -0
- package/dist/shared/globals/platform.js +1 -0
- package/dist/shared/globals/runtime.d.ts +1 -2
- package/dist/shared/globals/runtime.js +1 -2
- package/dist/shared/globals/web.js +5 -0
- package/dist/shared/request-context.d.ts +2 -0
- package/dist/shared/request-context.js +11 -0
- package/dist/shared/request-scope.d.ts +4 -0
- package/dist/shared/request-scope.js +14 -0
- package/dist/tooling/async.js +36 -14
- package/dist/tooling/shared.d.ts +1 -0
- package/dist/tooling/shared.js +26 -1
- package/dist/tooling/vite.js +8 -3
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +92 -13
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +4 -2
- package/native/ios/NetworkBridge.swift +11 -1
- package/native/ios/SocketBridge.swift +37 -2
- package/native/ios/WorkersCapacitorPlugin.swift +4 -0
- package/package.json +4 -2
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { storeHTTPOptions } from "./server-options.js";
|
|
2
|
+
import { WebSocket } from "../../browser/websocket/endpoint.js";
|
|
3
|
+
import { CloseEvent } from "../../browser/websocket/close-event.js";
|
|
1
4
|
import { asyncDispose } from "../../shared/globals/symbols.js";
|
|
2
5
|
// Copyright (c) 2017-2026 Cloudflare, Inc.
|
|
3
6
|
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
4
7
|
// https://opensource.org/licenses/Apache-2.0
|
|
5
8
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
6
9
|
// Adapted from workerd v1.20261012.1 node:http compatibility sources.
|
|
7
|
-
import { Readable, Writable } from "node:stream";
|
|
10
|
+
import { Readable, Writable, getDefaultHighWaterMark } from "node:stream";
|
|
8
11
|
import { EventEmitter } from "node:events";
|
|
9
12
|
import { Buffer } from "node:buffer";
|
|
10
13
|
import { ephemeral, hasHandler, kSetIncomingBody, kSetIncomingFetchResponse, kSetIncomingSocket, release, setHandler, } from "./registry.js";
|
|
14
|
+
import { validateInteger, validateString, validateBoolean, validateNumber, validateObject, validateOneOf, } from "../net/validators.js";
|
|
15
|
+
import { AbortError, ERR_INVALID_ARG_TYPE } from "../net/errors.js";
|
|
16
|
+
import { kIncomingMessage, kServerResponse, kUniqueHeaders, } from "./symbols.js";
|
|
17
|
+
import { parseUniqueHeadersOption } from "./unique-headers.js";
|
|
11
18
|
export const METHODS = [
|
|
12
19
|
"ACL",
|
|
13
20
|
"BIND",
|
|
@@ -116,12 +123,7 @@ function coded(error, code) {
|
|
|
116
123
|
}
|
|
117
124
|
function validateType(value, type, name) {
|
|
118
125
|
if (typeof value !== type)
|
|
119
|
-
throw
|
|
120
|
-
}
|
|
121
|
-
function validateInteger(value, name, minimum = Number.MIN_SAFE_INTEGER) {
|
|
122
|
-
validateType(value, "number", name);
|
|
123
|
-
if (!Number.isSafeInteger(value) || value < minimum)
|
|
124
|
-
throw coded(new RangeError(`${name} is out of range`), "ERR_OUT_OF_RANGE");
|
|
126
|
+
throw new ERR_INVALID_ARG_TYPE(name, type, value);
|
|
125
127
|
}
|
|
126
128
|
function unsupportedOption(name) {
|
|
127
129
|
throw coded(new Error(`The ${name} option is not implemented`), "ERR_OPTION_NOT_IMPLEMENTED");
|
|
@@ -129,18 +131,6 @@ function unsupportedOption(name) {
|
|
|
129
131
|
function notImplemented(name) {
|
|
130
132
|
return coded(new Error(`The ${name} method is not implemented`), "ERR_METHOD_NOT_IMPLEMENTED");
|
|
131
133
|
}
|
|
132
|
-
function validateString(value, name) {
|
|
133
|
-
if (typeof value !== "string")
|
|
134
|
-
throw coded(new TypeError(`The "${name}" argument must be of type string.`), "ERR_INVALID_ARG_TYPE");
|
|
135
|
-
}
|
|
136
|
-
function validateBoolean(value, name) {
|
|
137
|
-
if (typeof value !== "boolean")
|
|
138
|
-
throw coded(new TypeError(`The "${name}" argument must be of type boolean.`), "ERR_INVALID_ARG_TYPE");
|
|
139
|
-
}
|
|
140
|
-
function validateNumber(value, name) {
|
|
141
|
-
if (typeof value !== "number")
|
|
142
|
-
throw coded(new TypeError(`The "${name}" argument must be of type number.`), "ERR_INVALID_ARG_TYPE");
|
|
143
|
-
}
|
|
144
134
|
export function validateHeaderName(name, label = "Header name") {
|
|
145
135
|
if (typeof name !== "string" || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name))
|
|
146
136
|
throw coded(new TypeError(`${label} must be a valid HTTP token ["${String(name)}"]`), "ERR_INVALID_HTTP_TOKEN");
|
|
@@ -158,6 +148,7 @@ export class OutgoingMessage extends Writable {
|
|
|
158
148
|
strictContentLength = false;
|
|
159
149
|
bytesWritten = 0;
|
|
160
150
|
endingChunk = false;
|
|
151
|
+
#rejectNonStandardBodyWrites = false;
|
|
161
152
|
chunkedEncoding = false;
|
|
162
153
|
sendDate = false;
|
|
163
154
|
shouldKeepAlive = true;
|
|
@@ -182,6 +173,8 @@ export class OutgoingMessage extends Writable {
|
|
|
182
173
|
_onPendingData = () => { };
|
|
183
174
|
constructor(_req, options = {}) {
|
|
184
175
|
super({ autoDestroy: false, highWaterMark: options.highWaterMark });
|
|
176
|
+
this.#rejectNonStandardBodyWrites =
|
|
177
|
+
options.rejectNonStandardBodyWrites ?? false;
|
|
185
178
|
}
|
|
186
179
|
get headersSent() {
|
|
187
180
|
return this._header !== null || this._headerSent;
|
|
@@ -286,6 +279,13 @@ export class OutgoingMessage extends Writable {
|
|
|
286
279
|
throw coded(new Error(`Response body's content-length of ${total} byte(s) does not match the content-length of ${expected} byte(s) set in header`), "ERR_HTTP_CONTENT_LENGTH_MISMATCH");
|
|
287
280
|
this.bytesWritten = total;
|
|
288
281
|
}
|
|
282
|
+
#checkBodyAllowed() {
|
|
283
|
+
if (!this._hasBody &&
|
|
284
|
+
this.#rejectNonStandardBodyWrites &&
|
|
285
|
+
!this.finished &&
|
|
286
|
+
!this.destroyed)
|
|
287
|
+
throw coded(new Error("Request with GET/HEAD method cannot have body"), "ERR_HTTP_BODY_NOT_ALLOWED");
|
|
288
|
+
}
|
|
289
289
|
write(chunk, encoding, callback) {
|
|
290
290
|
if (chunk === null)
|
|
291
291
|
throw coded(new TypeError("May not write null values to stream"), "ERR_STREAM_NULL_VALUES");
|
|
@@ -295,6 +295,7 @@ export class OutgoingMessage extends Writable {
|
|
|
295
295
|
this.#checkContentLength(chunk, encoding, false);
|
|
296
296
|
if (!this._header && !this.finished && !this.destroyed)
|
|
297
297
|
this._implicitHeader();
|
|
298
|
+
this.#checkBodyAllowed();
|
|
298
299
|
return super.write(chunk, encoding, callback);
|
|
299
300
|
}
|
|
300
301
|
destroy(error) {
|
|
@@ -342,10 +343,20 @@ export class OutgoingMessage extends Writable {
|
|
|
342
343
|
!this.finished &&
|
|
343
344
|
!this.destroyed)
|
|
344
345
|
this._implicitHeader();
|
|
346
|
+
if (chunk &&
|
|
347
|
+
typeof chunk !== "function" &&
|
|
348
|
+
!this.finished &&
|
|
349
|
+
!this.destroyed) {
|
|
350
|
+
if (typeof chunk !== "string" && !(chunk instanceof Uint8Array))
|
|
351
|
+
throw new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk);
|
|
352
|
+
if (!this._header)
|
|
353
|
+
this._implicitHeader();
|
|
354
|
+
this.#checkBodyAllowed();
|
|
355
|
+
}
|
|
345
356
|
this.#checkContentLength(chunk, encoding, true);
|
|
346
357
|
this.endingChunk = true;
|
|
347
358
|
try {
|
|
348
|
-
super.end(chunk, encoding, callback);
|
|
359
|
+
super.end((chunk || undefined), encoding, callback);
|
|
349
360
|
}
|
|
350
361
|
finally {
|
|
351
362
|
this.endingChunk = false;
|
|
@@ -578,7 +589,9 @@ export class IncomingMessage extends Readable {
|
|
|
578
589
|
}
|
|
579
590
|
}, (error) => {
|
|
580
591
|
this.reading = false;
|
|
581
|
-
this.destroy(error
|
|
592
|
+
this.destroy(this.idleTimer && error instanceof TypeError
|
|
593
|
+
? new Error(error.message)
|
|
594
|
+
: error);
|
|
582
595
|
});
|
|
583
596
|
}
|
|
584
597
|
_destroy(error, callback) {
|
|
@@ -609,6 +622,13 @@ export class ServerResponse extends OutgoingMessage {
|
|
|
609
622
|
super(req, options);
|
|
610
623
|
this.req = req;
|
|
611
624
|
this.socket = req.socket;
|
|
625
|
+
this.once("finish", () => queueMicrotask(() => {
|
|
626
|
+
if (this._closed)
|
|
627
|
+
return;
|
|
628
|
+
this.destroyed = true;
|
|
629
|
+
this._closed = true;
|
|
630
|
+
this.emit("close");
|
|
631
|
+
}));
|
|
612
632
|
this.body = new ReadableStream({
|
|
613
633
|
start: (controller) => {
|
|
614
634
|
this.controller = controller;
|
|
@@ -740,10 +760,11 @@ export class Server extends EventEmitter {
|
|
|
740
760
|
rejectNonStandardBodyWrites = false;
|
|
741
761
|
keepAliveTimeout = 5_000;
|
|
742
762
|
keepAliveTimeoutBuffer = 1_000;
|
|
743
|
-
highWaterMark =
|
|
763
|
+
highWaterMark = getDefaultHighWaterMark(false);
|
|
744
764
|
port;
|
|
745
|
-
|
|
746
|
-
|
|
765
|
+
[kIncomingMessage] = IncomingMessage;
|
|
766
|
+
[kServerResponse] = ServerResponse;
|
|
767
|
+
[kUniqueHeaders] = null;
|
|
747
768
|
constructor(options, listener) {
|
|
748
769
|
super({ captureRejections: true });
|
|
749
770
|
this.emit = ((event, ...args) => {
|
|
@@ -764,63 +785,27 @@ export class Server extends EventEmitter {
|
|
|
764
785
|
}
|
|
765
786
|
return listeners.length !== 0;
|
|
766
787
|
});
|
|
767
|
-
if (
|
|
788
|
+
if (options != null)
|
|
789
|
+
storeHTTPOptions.call(this, options);
|
|
790
|
+
const values = options;
|
|
791
|
+
if (values?.highWaterMark !== undefined) {
|
|
792
|
+
validateNumber(values.highWaterMark, "options.highWaterMark");
|
|
793
|
+
if (values.highWaterMark > 0)
|
|
794
|
+
this.highWaterMark = values.highWaterMark;
|
|
795
|
+
}
|
|
796
|
+
if (typeof options === "function") {
|
|
768
797
|
listener = options;
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
for (const key of ["requestTimeout", "headersTimeout"]) {
|
|
777
|
-
if (options[key] !== undefined) {
|
|
778
|
-
validateInteger(options[key], key, 0);
|
|
779
|
-
this[key] = options[key];
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
this.headersTimeout =
|
|
783
|
-
options.headersTimeout ?? Math.min(60_000, this.requestTimeout);
|
|
784
|
-
if (this.headersTimeout > 0 &&
|
|
785
|
-
this.requestTimeout > 0 &&
|
|
786
|
-
this.headersTimeout > this.requestTimeout)
|
|
787
|
-
throw coded(new RangeError("headersTimeout must be <= requestTimeout"), "ERR_OUT_OF_RANGE");
|
|
788
|
-
for (const key of [
|
|
789
|
-
"keepAliveTimeout",
|
|
790
|
-
"keepAliveTimeoutBuffer",
|
|
791
|
-
"connectionsCheckingInterval",
|
|
792
|
-
]) {
|
|
793
|
-
if (options[key] !== undefined) {
|
|
794
|
-
validateInteger(options[key], key, key === "keepAliveTimeoutBuffer" ? Number.MIN_SAFE_INTEGER : 0);
|
|
795
|
-
unsupportedOption(key);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
for (const key of [
|
|
799
|
-
"insecureHTTPParser",
|
|
800
|
-
"requireHostHeader",
|
|
801
|
-
"joinDuplicateHeaders",
|
|
802
|
-
"rejectNonStandardBodyWrites",
|
|
803
|
-
])
|
|
804
|
-
if (options[key] !== undefined)
|
|
805
|
-
validateType(options[key], "boolean", key);
|
|
806
|
-
this.requireHostHeader = options.requireHostHeader ?? true;
|
|
807
|
-
this.joinDuplicateHeaders = options.joinDuplicateHeaders ?? false;
|
|
808
|
-
this.rejectNonStandardBodyWrites =
|
|
809
|
-
options.rejectNonStandardBodyWrites ?? false;
|
|
810
|
-
if (options.highWaterMark !== undefined) {
|
|
811
|
-
validateType(options.highWaterMark, "number", "highWaterMark");
|
|
812
|
-
if (options.highWaterMark > 0)
|
|
813
|
-
this.highWaterMark = options.highWaterMark;
|
|
814
|
-
}
|
|
815
|
-
if (options.IncomingMessage)
|
|
816
|
-
this.IncomingMessageClass =
|
|
817
|
-
options.IncomingMessage;
|
|
818
|
-
if (options.ServerResponse)
|
|
819
|
-
this.ServerResponseClass =
|
|
820
|
-
options.ServerResponse;
|
|
798
|
+
options = {};
|
|
799
|
+
}
|
|
800
|
+
else if (options == null) {
|
|
801
|
+
options = {};
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
validateObject(options, "options");
|
|
821
805
|
}
|
|
822
806
|
if (listener)
|
|
823
807
|
this.on("request", listener);
|
|
808
|
+
this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders);
|
|
824
809
|
}
|
|
825
810
|
[captureRejection](error, event, ...args) {
|
|
826
811
|
if (event === "request") {
|
|
@@ -852,8 +837,8 @@ export class Server extends EventEmitter {
|
|
|
852
837
|
setHandler(port, {
|
|
853
838
|
server: this,
|
|
854
839
|
createRequestResponse: () => ({
|
|
855
|
-
IncomingMessage: this
|
|
856
|
-
ServerResponse: this
|
|
840
|
+
IncomingMessage: this[kIncomingMessage],
|
|
841
|
+
ServerResponse: this[kServerResponse],
|
|
857
842
|
}),
|
|
858
843
|
});
|
|
859
844
|
const callback = [...args].reverse().find((arg) => typeof arg === "function") ??
|
|
@@ -943,14 +928,10 @@ export class Agent extends EventEmitter {
|
|
|
943
928
|
this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
|
|
944
929
|
this.maxFreeSockets = this.options.maxFreeSockets || 256;
|
|
945
930
|
this.scheduling = this.options.scheduling || "lifo";
|
|
946
|
-
|
|
947
|
-
throw coded(new TypeError("options.scheduling is invalid"), "ERR_INVALID_ARG_VALUE");
|
|
931
|
+
validateOneOf(this.scheduling, "scheduling", ["fifo", "lifo"]);
|
|
948
932
|
const maximum = this.options.maxTotalSockets;
|
|
949
|
-
if (maximum !== undefined)
|
|
950
|
-
validateNumber(maximum, "maxTotalSockets");
|
|
951
|
-
if (Number.isNaN(maximum) || maximum < 1)
|
|
952
|
-
throw coded(new RangeError("maxTotalSockets is out of range"), "ERR_OUT_OF_RANGE");
|
|
953
|
-
}
|
|
933
|
+
if (maximum !== undefined)
|
|
934
|
+
validateNumber(maximum, "maxTotalSockets", 1);
|
|
954
935
|
this.maxTotalSockets = maximum === undefined ? Infinity : maximum;
|
|
955
936
|
}
|
|
956
937
|
createConnection() {
|
|
@@ -996,8 +977,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
996
977
|
timeout;
|
|
997
978
|
_ended = false;
|
|
998
979
|
abortController = new AbortController();
|
|
999
|
-
upload;
|
|
1000
|
-
uploadWriter;
|
|
980
|
+
upload = [];
|
|
1001
981
|
response;
|
|
1002
982
|
timer;
|
|
1003
983
|
sent = false;
|
|
@@ -1093,10 +1073,11 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1093
1073
|
if (values.auth && !this.hasHeader("authorization"))
|
|
1094
1074
|
this.setHeader("Authorization", `Basic ${Buffer.from(values.auth).toString("base64")}`);
|
|
1095
1075
|
if (values.signal) {
|
|
1076
|
+
const onAbort = () => this.destroy(new AbortError(undefined, { cause: values.signal.reason }));
|
|
1096
1077
|
if (values.signal.aborted)
|
|
1097
|
-
|
|
1078
|
+
onAbort();
|
|
1098
1079
|
else
|
|
1099
|
-
values.signal.addEventListener("abort",
|
|
1080
|
+
values.signal.addEventListener("abort", onAbort, { once: true });
|
|
1100
1081
|
}
|
|
1101
1082
|
if (values.timeout !== undefined)
|
|
1102
1083
|
this.setTimeout(values.timeout);
|
|
@@ -1109,39 +1090,20 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1109
1090
|
this._header = `${this.method} ${this.path} HTTP/1.1\r\n`;
|
|
1110
1091
|
}
|
|
1111
1092
|
write(chunk, encoding, callback) {
|
|
1112
|
-
return super.write(chunk, encoding, callback);
|
|
1093
|
+
return super.write(chunk instanceof Uint8Array ? Buffer.from(chunk) : chunk, encoding, callback);
|
|
1113
1094
|
}
|
|
1114
1095
|
_write(chunk, encoding, callback) {
|
|
1115
1096
|
if (this.method === "GET" || this.method === "HEAD") {
|
|
1116
1097
|
callback();
|
|
1117
1098
|
return;
|
|
1118
1099
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
this.upload = new TransformStream();
|
|
1122
|
-
this.uploadWriter = this.upload.writable.getWriter();
|
|
1123
|
-
}
|
|
1124
|
-
this.#send();
|
|
1125
|
-
void this.uploadWriter.write(Buffer.from(chunk, encoding)).then(() => callback(), (error) => {
|
|
1126
|
-
this.destroy(error);
|
|
1127
|
-
callback(error);
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
catch (error) {
|
|
1131
|
-
this.destroy(error);
|
|
1132
|
-
callback(error);
|
|
1133
|
-
}
|
|
1100
|
+
this.upload.push(Buffer.from(chunk, encoding));
|
|
1101
|
+
callback();
|
|
1134
1102
|
}
|
|
1135
1103
|
_final = (callback) => {
|
|
1136
1104
|
try {
|
|
1137
1105
|
this.#send();
|
|
1138
|
-
|
|
1139
|
-
void this.uploadWriter.close().then(() => callback(), (error) => {
|
|
1140
|
-
this.destroy(error);
|
|
1141
|
-
callback(error);
|
|
1142
|
-
});
|
|
1143
|
-
else
|
|
1144
|
-
callback();
|
|
1106
|
+
callback();
|
|
1145
1107
|
}
|
|
1146
1108
|
catch (error) {
|
|
1147
1109
|
this.destroy(error);
|
|
@@ -1150,11 +1112,6 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1150
1112
|
};
|
|
1151
1113
|
flushHeaders = () => {
|
|
1152
1114
|
super.flushHeaders();
|
|
1153
|
-
if (this.method !== "GET" && this.method !== "HEAD" && !this.upload) {
|
|
1154
|
-
this.upload = new TransformStream();
|
|
1155
|
-
this.uploadWriter = this.upload.writable.getWriter();
|
|
1156
|
-
}
|
|
1157
|
-
this.#send();
|
|
1158
1115
|
};
|
|
1159
1116
|
#send() {
|
|
1160
1117
|
if (this.destroyed || this.sent)
|
|
@@ -1185,7 +1142,9 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1185
1142
|
: value
|
|
1186
1143
|
: [value])
|
|
1187
1144
|
headers.push([name, String(item)]);
|
|
1188
|
-
const body = this.upload
|
|
1145
|
+
const body = this.upload.length
|
|
1146
|
+
? new Blob(this.upload)
|
|
1147
|
+
: null;
|
|
1189
1148
|
const response = missingHost
|
|
1190
1149
|
? Promise.resolve(new Response(null, {
|
|
1191
1150
|
status: 400,
|
|
@@ -1265,10 +1224,8 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1265
1224
|
this.destroy(coded(new Error("The operation was aborted"), "ABORT_ERR"));
|
|
1266
1225
|
}, this.timeout);
|
|
1267
1226
|
}
|
|
1268
|
-
#releaseUpload(
|
|
1269
|
-
|
|
1270
|
-
this.uploadWriter = undefined;
|
|
1271
|
-
this.upload = undefined;
|
|
1227
|
+
#releaseUpload(_error) {
|
|
1228
|
+
this.upload = [];
|
|
1272
1229
|
}
|
|
1273
1230
|
#emitClose() {
|
|
1274
1231
|
if (!this._closed) {
|
|
@@ -1329,8 +1286,7 @@ export function setMaxIdleHTTPParsers(max) {
|
|
|
1329
1286
|
export function _connectionListener() {
|
|
1330
1287
|
throw notImplemented("_connectionListener");
|
|
1331
1288
|
}
|
|
1332
|
-
export
|
|
1333
|
-
export const CloseEvent = globalThis.CloseEvent;
|
|
1289
|
+
export { WebSocket, CloseEvent };
|
|
1334
1290
|
export const MessageEvent = globalThis.MessageEvent;
|
|
1335
1291
|
export default {
|
|
1336
1292
|
validateHeaderName,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function storeHTTPOptions(this: any, options: any): void;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
5
|
+
// Shared by node:http and node:_http_server; read options in pinned Workers order.
|
|
6
|
+
import { IncomingMessage, ServerResponse } from "./index.js";
|
|
7
|
+
import { kIncomingMessage, kServerResponse } from "./symbols.js";
|
|
8
|
+
import { validateInteger, validateBoolean } from "../net/validators.js";
|
|
9
|
+
import { ERR_OUT_OF_RANGE } from "../net/errors.js";
|
|
10
|
+
function unsupportedOption(name) {
|
|
11
|
+
throw Object.assign(new Error(`The ${name} option is not implemented`), {
|
|
12
|
+
code: "ERR_OPTION_NOT_IMPLEMENTED",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function storeHTTPOptions(options) {
|
|
16
|
+
this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
|
|
17
|
+
this[kServerResponse] = options.ServerResponse || ServerResponse;
|
|
18
|
+
const maxHeaderSize = options.maxHeaderSize;
|
|
19
|
+
if (maxHeaderSize !== undefined) {
|
|
20
|
+
validateInteger(maxHeaderSize, "maxHeaderSize", 0);
|
|
21
|
+
unsupportedOption("maxHeaderSize");
|
|
22
|
+
}
|
|
23
|
+
const insecureHTTPParser = options.insecureHTTPParser;
|
|
24
|
+
if (insecureHTTPParser !== undefined) {
|
|
25
|
+
// If enabled it will use a HTTP parser with leniency flags enabled.
|
|
26
|
+
// Since our implementation does not use any http parser, and uses "fetch" API,
|
|
27
|
+
// it doesn't make sense to support this option.
|
|
28
|
+
validateBoolean(insecureHTTPParser, "options.insecureHTTPParser");
|
|
29
|
+
}
|
|
30
|
+
const requestTimeout = options.requestTimeout;
|
|
31
|
+
if (requestTimeout !== undefined) {
|
|
32
|
+
validateInteger(requestTimeout, "requestTimeout", 0);
|
|
33
|
+
this.requestTimeout = requestTimeout;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.requestTimeout = 300_000; // 5 minutes
|
|
37
|
+
}
|
|
38
|
+
const headersTimeout = options.headersTimeout;
|
|
39
|
+
if (headersTimeout !== undefined) {
|
|
40
|
+
validateInteger(headersTimeout, "headersTimeout", 0);
|
|
41
|
+
this.headersTimeout = headersTimeout;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.headersTimeout = Math.min(60_000, this.requestTimeout); // Minimum between 60 seconds or requestTimeout
|
|
45
|
+
}
|
|
46
|
+
if (this.requestTimeout > 0 &&
|
|
47
|
+
this.headersTimeout > 0 &&
|
|
48
|
+
this.headersTimeout > this.requestTimeout) {
|
|
49
|
+
throw new ERR_OUT_OF_RANGE("headersTimeout", "<= requestTimeout", headersTimeout);
|
|
50
|
+
}
|
|
51
|
+
const keepAliveTimeout = options.keepAliveTimeout;
|
|
52
|
+
if (keepAliveTimeout !== undefined) {
|
|
53
|
+
validateInteger(keepAliveTimeout, "keepAliveTimeout", 0);
|
|
54
|
+
unsupportedOption("keepAliveTimeout");
|
|
55
|
+
}
|
|
56
|
+
const keepAliveTimeoutBuffer = options.keepAliveTimeoutBuffer;
|
|
57
|
+
if (keepAliveTimeoutBuffer !== undefined) {
|
|
58
|
+
validateInteger(keepAliveTimeoutBuffer, "keepAliveTimeoutBuffer");
|
|
59
|
+
unsupportedOption("keepAliveTimeoutBuffer");
|
|
60
|
+
}
|
|
61
|
+
const connectionsCheckingInterval = options.connectionsCheckingInterval;
|
|
62
|
+
if (connectionsCheckingInterval !== undefined) {
|
|
63
|
+
validateInteger(connectionsCheckingInterval, "connectionsCheckingInterval", 0);
|
|
64
|
+
unsupportedOption("connectionsCheckingInterval");
|
|
65
|
+
}
|
|
66
|
+
const requireHostHeader = options.requireHostHeader;
|
|
67
|
+
if (requireHostHeader !== undefined) {
|
|
68
|
+
validateBoolean(requireHostHeader, "options.requireHostHeader");
|
|
69
|
+
this.requireHostHeader = requireHostHeader;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.requireHostHeader = true;
|
|
73
|
+
}
|
|
74
|
+
const joinDuplicateHeaders = options.joinDuplicateHeaders;
|
|
75
|
+
if (joinDuplicateHeaders !== undefined) {
|
|
76
|
+
validateBoolean(joinDuplicateHeaders, "options.joinDuplicateHeaders");
|
|
77
|
+
}
|
|
78
|
+
this.joinDuplicateHeaders = joinDuplicateHeaders ?? false;
|
|
79
|
+
const rejectNonStandardBodyWrites = options.rejectNonStandardBodyWrites;
|
|
80
|
+
if (rejectNonStandardBodyWrites !== undefined) {
|
|
81
|
+
validateBoolean(rejectNonStandardBodyWrites, "options.rejectNonStandardBodyWrites");
|
|
82
|
+
this.rejectNonStandardBodyWrites = rejectNonStandardBodyWrites;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.rejectNonStandardBodyWrites = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const kIncomingMessage: unique symbol;
|
|
2
|
+
export declare const kServerResponse: unique symbol;
|
|
3
|
+
export declare const kUniqueHeaders: unique symbol;
|
|
4
|
+
export declare const kHighWaterMark: unique symbol;
|
|
5
|
+
export declare const kConnectionsCheckingInterval: unique symbol;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
5
|
+
export const kIncomingMessage = Symbol("IncomingMessage");
|
|
6
|
+
export const kServerResponse = Symbol("ServerResponse");
|
|
7
|
+
export const kUniqueHeaders = Symbol("kUniqueHeaders");
|
|
8
|
+
export const kHighWaterMark = Symbol("kHighWaterMark");
|
|
9
|
+
export const kConnectionsCheckingInterval = Symbol("http.server.connectionsCheckingInterval");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseUniqueHeadersOption(headers?: (string | string[])[]): Set<string> | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
5
|
+
export function parseUniqueHeadersOption(headers) {
|
|
6
|
+
if (!Array.isArray(headers)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const unique = new Set();
|
|
10
|
+
for (const header of headers) {
|
|
11
|
+
if (Array.isArray(header)) {
|
|
12
|
+
for (const h of header) {
|
|
13
|
+
unique.add(h.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
unique.add(header.toLowerCase());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return unique;
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { METHODS as methods } from "../http/index.js";
|
|
2
|
+
import { kIncomingMessage } from "../http/symbols.js";
|
|
3
|
+
export { methods, kIncomingMessage };
|
|
4
|
+
/**
|
|
5
|
+
* Verifies that the given val is a valid HTTP token
|
|
6
|
+
* per the rules defined in RFC 7230
|
|
7
|
+
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
|
|
8
|
+
*/
|
|
9
|
+
export declare function _checkIsHttpToken(val: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* True if val contains an invalid field-vchar
|
|
12
|
+
* field-value = *( field-content / obs-fold )
|
|
13
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
14
|
+
* field-vchar = VCHAR / obs-text
|
|
15
|
+
*/
|
|
16
|
+
export declare function _checkInvalidHeaderChar(val: number | string | ReadonlyArray<string>): boolean;
|
|
17
|
+
export declare const CRLF = "\r\n";
|
|
18
|
+
export declare const chunkExpression: RegExp;
|
|
19
|
+
export declare const continueExpression: RegExp;
|
|
20
|
+
export declare const parsers: {
|
|
21
|
+
name: string;
|
|
22
|
+
max: number;
|
|
23
|
+
};
|
|
24
|
+
declare const _default: {
|
|
25
|
+
_checkIsHttpToken: typeof _checkIsHttpToken;
|
|
26
|
+
_checkInvalidHeaderChar: typeof _checkInvalidHeaderChar;
|
|
27
|
+
chunkExpression: RegExp;
|
|
28
|
+
kIncomingMessage: symbol;
|
|
29
|
+
CRLF: string;
|
|
30
|
+
continueExpression: RegExp;
|
|
31
|
+
methods: string[];
|
|
32
|
+
parsers: {
|
|
33
|
+
name: string;
|
|
34
|
+
max: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export default _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
5
|
+
import { METHODS as methods } from "../http/index.js";
|
|
6
|
+
import { kIncomingMessage } from "../http/symbols.js";
|
|
7
|
+
export { methods, kIncomingMessage };
|
|
8
|
+
const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
|
|
9
|
+
/**
|
|
10
|
+
* Verifies that the given val is a valid HTTP token
|
|
11
|
+
* per the rules defined in RFC 7230
|
|
12
|
+
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
|
|
13
|
+
*/
|
|
14
|
+
export function _checkIsHttpToken(val) {
|
|
15
|
+
return tokenRegExp.test(val);
|
|
16
|
+
}
|
|
17
|
+
const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
|
|
18
|
+
/**
|
|
19
|
+
* True if val contains an invalid field-vchar
|
|
20
|
+
* field-value = *( field-content / obs-fold )
|
|
21
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
22
|
+
* field-vchar = VCHAR / obs-text
|
|
23
|
+
*/
|
|
24
|
+
export function _checkInvalidHeaderChar(val) {
|
|
25
|
+
if (Array.isArray(val)) {
|
|
26
|
+
return val.some((v) => headerCharRegex.test(v));
|
|
27
|
+
}
|
|
28
|
+
return headerCharRegex.test(`${val}`);
|
|
29
|
+
}
|
|
30
|
+
export const CRLF = "\r\n";
|
|
31
|
+
export const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
|
|
32
|
+
export const continueExpression = /(?:^|\W)100-continue(?:$|\W)/i;
|
|
33
|
+
export const parsers = { name: "parsers", max: 1000 };
|
|
34
|
+
export default {
|
|
35
|
+
_checkIsHttpToken,
|
|
36
|
+
_checkInvalidHeaderChar,
|
|
37
|
+
chunkExpression,
|
|
38
|
+
kIncomingMessage,
|
|
39
|
+
CRLF,
|
|
40
|
+
continueExpression,
|
|
41
|
+
methods,
|
|
42
|
+
parsers,
|
|
43
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OutgoingMessage, validateHeaderName, validateHeaderValue } from "../http/index.js";
|
|
2
|
+
import { kUniqueHeaders, kHighWaterMark } from "../http/symbols.js";
|
|
3
|
+
export { OutgoingMessage, validateHeaderName, validateHeaderValue, kUniqueHeaders, kHighWaterMark, };
|
|
4
|
+
import { parseUniqueHeadersOption } from "../http/unique-headers.js";
|
|
5
|
+
export { parseUniqueHeadersOption };
|
|
6
|
+
declare const _default: {
|
|
7
|
+
OutgoingMessage: typeof OutgoingMessage;
|
|
8
|
+
validateHeaderName: typeof validateHeaderName;
|
|
9
|
+
validateHeaderValue: typeof validateHeaderValue;
|
|
10
|
+
kUniqueHeaders: symbol;
|
|
11
|
+
kHighWaterMark: symbol;
|
|
12
|
+
parseUniqueHeadersOption: typeof parseUniqueHeadersOption;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
2
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
3
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
4
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
5
|
+
import { OutgoingMessage, validateHeaderName, validateHeaderValue, } from "../http/index.js";
|
|
6
|
+
import { kUniqueHeaders, kHighWaterMark } from "../http/symbols.js";
|
|
7
|
+
export { OutgoingMessage, validateHeaderName, validateHeaderValue, kUniqueHeaders, kHighWaterMark, };
|
|
8
|
+
import { parseUniqueHeadersOption } from "../http/unique-headers.js";
|
|
9
|
+
export { parseUniqueHeadersOption };
|
|
10
|
+
export default {
|
|
11
|
+
OutgoingMessage,
|
|
12
|
+
validateHeaderName,
|
|
13
|
+
validateHeaderValue,
|
|
14
|
+
kUniqueHeaders,
|
|
15
|
+
kHighWaterMark,
|
|
16
|
+
parseUniqueHeadersOption,
|
|
17
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { storeHTTPOptions } from "../http/server-options.js";
|
|
2
|
+
import { Server, ServerResponse, STATUS_CODES, _connectionListener } from "../http/index.js";
|
|
3
|
+
import { kServerResponse, kConnectionsCheckingInterval } from "../http/symbols.js";
|
|
4
|
+
export { Server, ServerResponse, STATUS_CODES, kServerResponse, kConnectionsCheckingInterval, _connectionListener, };
|
|
5
|
+
export declare function setupConnectionsTracking(): never;
|
|
6
|
+
export { storeHTTPOptions };
|
|
7
|
+
export declare function httpServerPreClose(server: any): void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
Server: typeof Server;
|
|
10
|
+
ServerResponse: typeof ServerResponse;
|
|
11
|
+
STATUS_CODES: Record<number, string>;
|
|
12
|
+
kServerResponse: symbol;
|
|
13
|
+
kConnectionsCheckingInterval: symbol;
|
|
14
|
+
_connectionListener: typeof _connectionListener;
|
|
15
|
+
setupConnectionsTracking: typeof setupConnectionsTracking;
|
|
16
|
+
httpServerPreClose: typeof httpServerPreClose;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { storeHTTPOptions } from "../http/server-options.js";
|
|
2
|
+
// Copyright (c) 2017-2022 Cloudflare, Inc.
|
|
3
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
4
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
5
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
6
|
+
import { Server, ServerResponse, STATUS_CODES, _connectionListener, } from "../http/index.js";
|
|
7
|
+
import { kServerResponse, kConnectionsCheckingInterval, } from "../http/symbols.js";
|
|
8
|
+
export { Server, ServerResponse, STATUS_CODES, kServerResponse, kConnectionsCheckingInterval, _connectionListener, };
|
|
9
|
+
export function setupConnectionsTracking() {
|
|
10
|
+
throw Object.assign(new Error("The setupConnectionsTracking method is not implemented"), { code: "ERR_METHOD_NOT_IMPLEMENTED" });
|
|
11
|
+
}
|
|
12
|
+
export { storeHTTPOptions };
|
|
13
|
+
export function httpServerPreClose(server) {
|
|
14
|
+
server.closeIdleConnections();
|
|
15
|
+
clearInterval(server[kConnectionsCheckingInterval]);
|
|
16
|
+
}
|
|
17
|
+
export default {
|
|
18
|
+
Server,
|
|
19
|
+
ServerResponse,
|
|
20
|
+
STATUS_CODES,
|
|
21
|
+
kServerResponse,
|
|
22
|
+
kConnectionsCheckingInterval,
|
|
23
|
+
_connectionListener,
|
|
24
|
+
setupConnectionsTracking,
|
|
25
|
+
httpServerPreClose,
|
|
26
|
+
};
|