pass through all the valid headers when proxing the WebSocket, and adds related test cases

This commit is contained in:
砚然
2018-03-23 15:42:38 +08:00
parent 11e68100a4
commit aae5c9b039
6 changed files with 115 additions and 46 deletions

View File

@@ -187,17 +187,20 @@ function doUpload(url, method, filepath, formParams, headers = {}, isProxy) {
return requestTask;
}
function doWebSocket(url, isProxy) {
function doWebSocket(url, headers = {}, isProxy) {
let ws;
if (isProxy) {
headers['via-proxy'] = 'true';
const agent = new HttpsProxyAgent(SOCKET_PROXY_HOST);
ws = new WebSocket(url, {
agent,
rejectUnauthorized: false
rejectUnauthorized: false,
headers
});
} else {
ws = new WebSocket(url, {
rejectUnauthorized: false
rejectUnauthorized: false,
headers
});
}
@@ -252,12 +255,12 @@ function directOptions(url, headers = {}) {
return directRequest('OPTIONS', url, {}, headers);
}
function proxyWs(url) {
return doWebSocket(url, true);
function proxyWs(url, headers) {
return doWebSocket(url, headers, true);
}
function directWs(url) {
return doWebSocket(url);
function directWs(url, headers) {
return doWebSocket(url, headers);
}
/**