summaryrefslogtreecommitdiff
path: root/ext/node/polyfills
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-07-21 02:18:07 +0200
committerGitHub <noreply@github.com>2023-07-21 02:18:07 +0200
commitda709729e3dd6f310182581ca1c6380ad51443fc (patch)
treee4b49ed701938a9abd98631ffeb9b9a2fced0257 /ext/node/polyfills
parent5ff040bf59b1665f0545f9b6e732b027ab676446 (diff)
fix(node/http): add encrypted field to FakeSocket (#19886)
Fixes #19557
Diffstat (limited to 'ext/node/polyfills')
-rw-r--r--ext/node/polyfills/http.ts26
-rw-r--r--ext/node/polyfills/https.ts3
2 files changed, 19 insertions, 10 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 17ab8ce31..bba11cdc1 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -278,6 +278,7 @@ class FakeSocket extends EventEmitter {
super();
this.remoteAddress = opts.hostname;
this.remotePort = opts.port;
+ this.encrypted = opts.encrypted;
}
setKeepAlive() {}
@@ -561,7 +562,7 @@ class ClientRequest extends OutgoingMessage {
this.onSocket(createConnection(optsWithoutSignal));
}
}*/
- this.onSocket(new FakeSocket());
+ this.onSocket(new FakeSocket({ encrypted: this._encrypted }));
const url = this._createUrlStrFromOptions();
@@ -1306,7 +1307,10 @@ export class ServerResponse extends NodeWritable {
return status === 101 || status === 204 || status === 205 || status === 304;
}
- constructor(resolve: (value: Response | PromiseLike<Response>) => void) {
+ constructor(
+ resolve: (value: Response | PromiseLike<Response>) => void,
+ socket: FakeSocket,
+ ) {
let controller: ReadableByteStreamController;
const readable = new ReadableStream({
start(c) {
@@ -1349,7 +1353,7 @@ export class ServerResponse extends NodeWritable {
});
this.#readable = readable;
this.#resolve = resolve;
- this.socket = new FakeSocket();
+ this.socket = socket;
}
setHeader(name: string, value: string) {
@@ -1438,7 +1442,7 @@ export class IncomingMessageForServer extends NodeReadable {
// These properties are used by `npm:forwarded` for example.
socket: { remoteAddress: string; remotePort: number };
- constructor(req: Request, remoteAddr: { hostname: string; port: number }) {
+ constructor(req: Request, socket: FakeSocket) {
// Check if no body (GET/HEAD/OPTIONS/...)
const reader = req.body?.getReader();
super({
@@ -1465,10 +1469,7 @@ export class IncomingMessageForServer extends NodeReadable {
// url: (new URL(request.url).pathname),
this.url = req.url?.slice(req.url.indexOf("/", 8));
this.method = req.method;
- this.socket = new FakeSocket({
- remoteAddress: remoteAddr.hostname,
- remotePort: remoteAddr.port,
- });
+ this.socket = socket;
this.#req = req;
}
@@ -1572,7 +1573,12 @@ export class ServerImpl extends EventEmitter {
_serve() {
const ac = new AbortController();
const handler = (request: Request, info: Deno.ServeHandlerInfo) => {
- const req = new IncomingMessageForServer(request, info.remoteAddr);
+ const socket = new FakeSocket({
+ remoteAddress: info.remoteAddr.hostname,
+ remotePort: info.remoteAddr.port,
+ encrypted: this._encrypted,
+ });
+ const req = new IncomingMessageForServer(request, socket);
if (req.upgrade && this.listenerCount("upgrade") > 0) {
const { conn, response } = upgradeHttpRaw(request);
const socket = new Socket({
@@ -1582,7 +1588,7 @@ export class ServerImpl extends EventEmitter {
return response;
} else {
return new Promise<Response>((resolve): void => {
- const res = new ServerResponse(resolve);
+ const res = new ServerResponse(resolve, socket);
this.emit("request", req, res);
});
}
diff --git a/ext/node/polyfills/https.ts b/ext/node/polyfills/https.ts
index c504f0874..46d4bd087 100644
--- a/ext/node/polyfills/https.ts
+++ b/ext/node/polyfills/https.ts
@@ -50,6 +50,8 @@ export class Server extends HttpServer {
: this._opts.key,
};
}
+
+ _encrypted = true;
}
export function createServer(opts, requestListener?: ServerHandler) {
return new Server(opts, requestListener);
@@ -110,6 +112,7 @@ const globalAgent = new Agent({
/** HttpsClientRequest class loosely follows http.ClientRequest class API. */
class HttpsClientRequest extends ClientRequest {
+ override _encrypted: true;
override defaultProtocol = "https:";
override _getClient(): Deno.HttpClient | undefined {
if (caCerts === null) {