mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
chore: update test code for websocket
This commit is contained in:
@@ -84,7 +84,7 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
|
||||
const clientMsgQueue = [];
|
||||
const serverInfo = getWsReqInfo(wsReq);
|
||||
// proxy-layer websocket client
|
||||
const proxyWs = new WebSocket(serverInfo.url, '', {
|
||||
const proxyWs = new WebSocket(serverInfo.url, {
|
||||
rejectUnauthorized: !self.dangerouslyIgnoreUnauthorized,
|
||||
headers: serverInfo.noWsHeaders
|
||||
});
|
||||
@@ -106,13 +106,8 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
|
||||
*/
|
||||
const sendProxyMessage = (finalMsg) => {
|
||||
const message = finalMsg.data;
|
||||
if (proxyWs.readyState === 1) {
|
||||
// if there still are msg queue consuming, keep it going
|
||||
if (clientMsgQueue.length > 0) {
|
||||
clientMsgQueue.push(message);
|
||||
} else {
|
||||
proxyWs.send(message);
|
||||
}
|
||||
if (proxyWs.readyState === 1 && clientMsgQueue.length === 0) {
|
||||
proxyWs.send(message);
|
||||
} else {
|
||||
clientMsgQueue.push(message);
|
||||
}
|
||||
@@ -120,7 +115,6 @@ function handleWs(userRule, recorder, wsClient, wsReq) {
|
||||
|
||||
/**
|
||||
* consume the message in queue when the proxy ws is not ready yet
|
||||
* will handle them from the first one-by-one
|
||||
*/
|
||||
const consumeMsgQueue = () => {
|
||||
while (clientMsgQueue.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user