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

Support proxying custom WebSocket sub protocols #559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions lib/requestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
function getWsReqInfo(wsReq) {
const headers = wsReq.headers || {};
const host = headers.host;
const wsProtocol = headers['sec-websocket-protocol'] || '';
const hostName = host.split(':')[0];
const port = host.split(':')[1];

Expand Down Expand Up @@ -248,7 +249,8 @@ function getWsReqInfo(wsReq) {
hostName: hostName,
port: port,
path: path,
protocol: isEncript ? 'wss' : 'ws'
protocol: isEncript ? 'wss' : 'ws',
wsProtocol: wsProtocol
};
}
/**
Expand Down Expand Up @@ -712,7 +714,7 @@ function getWsHandler(userRule, recorder, wsClient, wsReq) {
const serverInfo = getWsReqInfo(wsReq);
const serverInfoPort = serverInfo.port ? `:${serverInfo.port}` : '';
const wsUrl = `${serverInfo.protocol}://${serverInfo.hostName}${serverInfoPort}${serverInfo.path}`;
const proxyWs = new WebSocket(wsUrl, '', {
const proxyWs = new WebSocket(wsUrl, serverInfo.wsProtocol, {
rejectUnauthorized: !self.dangerouslyIgnoreUnauthorized,
headers: serverInfo.noWsHeaders
});
Expand Down