Open
Conversation
azu
reviewed
Jun 20, 2019
azu
left a comment
There was a problem hiding this comment.
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.
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官方已经放弃维护了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add two rules: