-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: support hooks on websocket #486
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this pull request ❤️
I have tested this patch on https://www.websocket.org/echo.html with following script.
It work!
module.exports = {
summary: 'WebSocket Rule',
* beforeDealHttpsRequest(requestDetail) {
return requestDetail.host === "echo.websocket.org:443";
},
* beforeSendWsMessageToClient(requestDetail) {
return {
data: 'replaced by beforeSendWsMessageToClient'
}
}
};
* get request info from the ws client | ||
* @param @required wsClient the ws client of WebSocket | ||
*/ | ||
function getWsReqInfo(wsReq) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that some weboscet url has not :{port}
.
So, you need to normalize port
before building url
.
/**
* get request info from the ws client
* @param @required wsClient the ws client of WebSocket
*/
function getWsReqInfo(wsReq) {
const headers = wsReq.headers || {};
const host = headers.host;
const hostname = host.split(':')[0];
const port = host.split(':')[1];
// https://github.com/alibaba/anyproxy/pull/450
const portPart = port ? `:${port}` : '';
// TODO 如果是windows机器,url是不是全路径?需要对其过滤,取出
const path = wsReq.url || '/';
const isEncript = wsReq.connection && wsReq.connection.encrypted;
return {
url: `${isEncript ? 'wss' : 'ws'}://${hostname}${portPart}${path}`,
headers: headers, // the full headers of origin ws connection
noWsHeaders: getNoWsHeaders(headers),
secure: Boolean(isEncript),
hostname: hostname,
port: port,
path: path
};
}
ref #450
This changes is patched and this ws proxy work on https://www.websocket.org/echo.html.
Exc me , can I ask that how to set the websocket port? |
Will this PR be further processed? I am also looking forward to websocket hook functions! 🙏 |
感觉anyproxy官方已经放弃维护了 |
add two rules: