fix: Use encrypted field to check for TLS.

This commit is contained in:
Ruben Verborgh
2022-06-23 13:24:50 +01:00
committed by Joachim Van Herwegen
parent bc088f494d
commit 82f90709a6
2 changed files with 3 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import { EventEmitter } from 'events';
import type { TLSSocket } from 'tls';
import type { WebSocket } from 'ws';
import { getLoggerFor } from '../logging/LogUtil';
import type { HttpRequest } from '../server/HttpRequest';
@@ -47,7 +48,7 @@ class WebSocketListener extends EventEmitter {
// Store the HTTP host and protocol
const forwarded = parseForwarded(headers);
this.host = forwarded.host ?? headers.host ?? 'localhost';
this.protocol = forwarded.proto === 'https' || (socket as any).secure ? 'https:' : 'http:';
this.protocol = forwarded.proto === 'https' || (socket as TLSSocket).encrypted ? 'https:' : 'http:';
}
private stop(): void {