Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced WebSocket Protocol Handling in Proxy Server Connections #304

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,21 +868,29 @@ export class Proxy implements IProxy {
} else {
url = upgradeReq.url;
}
const ptosHeaders = {};
const ctopHeaders = upgradeReq.headers;
for (const key in ctopHeaders) {
if (key.indexOf("sec-websocket") !== 0) {
ptosHeaders[key] = ctopHeaders[key];
const proxyToServerHeaders= {};
const clientToProxyHeaders = upgradeReq.headers;
for (const header in clientToProxyHeaders) {
if (header.indexOf("sec-websocket") !== 0) {
proxyToServerHeaders[header] = clientToProxyHeaders[header];
}
}

let protocols: string[] = [];
if(clientToProxyHeaders["sec-websocket-protocol"]) {
protocols = clientToProxyHeaders["sec-websocket-protocol"].split(",").map((p) => p.trim());
}

ctx.proxyToServerWebSocketOptions = {
url,
protocols: protocols.length > 0 ? protocols : undefined,
agent: ctx.isSSL ? self.httpsAgent : self.httpAgent,
headers: ptosHeaders,
headers: proxyToServerHeaders,
};
function makeProxyToServerWebSocket() {
ctx.proxyToServerWebSocket = new WebSocket(
ctx.proxyToServerWebSocketOptions!.url!,
ctx.proxyToServerWebSocketOptions.protocols,
ctx.proxyToServerWebSocketOptions
);
ctx.proxyToServerWebSocket.on(
Expand Down
Loading