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 { EventEmitter } from 'events';
import type { TLSSocket } from 'tls';
import type { WebSocket } from 'ws'; import type { WebSocket } from 'ws';
import { getLoggerFor } from '../logging/LogUtil'; import { getLoggerFor } from '../logging/LogUtil';
import type { HttpRequest } from '../server/HttpRequest'; import type { HttpRequest } from '../server/HttpRequest';
@ -47,7 +48,7 @@ class WebSocketListener extends EventEmitter {
// Store the HTTP host and protocol // Store the HTTP host and protocol
const forwarded = parseForwarded(headers); const forwarded = parseForwarded(headers);
this.host = forwarded.host ?? headers.host ?? 'localhost'; 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 { private stop(): void {

View File

@ -25,7 +25,7 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
'sec-websocket-protocol': 'solid-0.1, other/1.0.0', 'sec-websocket-protocol': 'solid-0.1, other/1.0.0',
}, },
socket: { socket: {
secure: true, encrypted: true,
}, },
} as any as HttpRequest; } as any as HttpRequest;
await protocol.handle({ webSocket, upgradeRequest } as any); await protocol.handle({ webSocket, upgradeRequest } as any);