summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/polyfills/http.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 12d71277f..9104183ca 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -552,8 +552,11 @@ export class IncomingMessageForServer extends NodeReadable {
#req: Request;
url: string;
method: string;
+ // Polyfills part of net.Socket object.
+ // These properties are used by `npm:forwarded` for example.
+ socket: { remoteAddress: string; remotePort: number };
- constructor(req: Request) {
+ constructor(req: Request, conn: Deno.Conn) {
// Check if no body (GET/HEAD/OPTIONS/...)
const reader = req.body?.getReader();
super({
@@ -580,6 +583,10 @@ 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 = {
+ remoteAddress: conn.remoteAddr.hostname,
+ remotePort: conn.remoteAddr.port,
+ };
this.#req = req;
}
@@ -601,6 +608,11 @@ export class IncomingMessageForServer extends NodeReadable {
this.#req.headers.get("upgrade"),
);
}
+
+ // connection is deprecated, but still tested in unit test.
+ get connection() {
+ return this.socket;
+ }
}
type ServerHandler = (
@@ -669,7 +681,7 @@ class ServerImpl extends EventEmitter {
if (reqEvent === null) {
break;
}
- const req = new IncomingMessageForServer(reqEvent.request);
+ const req = new IncomingMessageForServer(reqEvent.request, tcpConn);
if (req.upgrade && this.listenerCount("upgrade") > 0) {
const conn = await denoHttp.upgradeHttpRaw(
reqEvent.request,