Setting up WebSocket protocol
See original GitHub issueHi, when I use browsermob-proxy all connections goes through https:// even WebSocket methods. For example: GET /echo HTTP/1.1 returns WebSocket-Location: wss://site.com/echo/123/websocket, after that initiates GET wss😕/site.com/echo/123/websocket with response code 101 switching protocols. But with browsermob-proxy initiates request GET https😕/site.com/echo/123/websocket
I’ve try to change protocol with addRequestFilter() but there is only http version of protocol:
proxy.addRequestFilter(new RequestFilter() {
@Override
public HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {
if (request.getUri().contains("echo/") && request.getUri().contains("/websocket")) {
request.setProtocolVersion(new HttpVersion("WSS/1.1", true));
}
return null;
}
});
There is no info about WebSocket and browsermob-proxy just this self-reply https://groups.google.com/forum/#!topic/browsermob-proxy/JzTHxje0qP4
I need proxy to monitor HTTP and WebSocket, there are a lot of autotests that I could make with it, but if I run tests with WebSocket it does not work at all.
Kind regards!
Issue Analytics
- State:
- Created 7 years ago
- Comments:14
@jekh Looks like littleproxy supports WebSockets already https://github.com/adamfisk/LittleProxy/releases/tag/littleproxy-1.1.0 Could somebody take a look at this issue?
Thank you for this workaround. I had to tweak it a little bit since Chrome and Windows blocks the file:// schema usage for pac file url and I did not want to start a webserver to host the pac file. I found the solution here: https://superuser.com/questions/1405499/chrome-72-seems-to-no-longer-accept-proxy-pac-url
--proxy-pac-url='data:application/x-javascript-config;base64,'$(base64 -w0 /path/to/local/proxy.pac)
The code after this trick has been applied:// Create PAC file to send WebSocket requests direct but other protocols throught BrowserMobProxy server String pacFunction = "function FindProxyForURL(url, host) { if (url.substring(0, 3) === "ws:" || url.substring(0, 4) === "wss:") { " + "return "DIRECT"; } else { return "PROXY localhost:" + proxyPort + ""; } }"; seleniumProxy.setProxyAutoconfigUrl("data:application/x-javascript-config;base64," + Base64.getUrlEncoder().encodeToString(pacFunction.getBytes()));
As you can see I encoded the script not the location because that way it did not work for me. Note: Actually I used BrowserUp proxy but I think this should work with BrowserMob also.