-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Websocket proxy failed "Error during WebSocket handshake" #72
Comments
I think I'm having the same issue here, when I try to connect through the ASP proxy, I get a HTTP 502 on my websocket client. I've created very simple test server and clients in node.js to try and debug if it's something we're doing on that end that would interfere, but still can't get it to work. Any direction as to where to go from here would be greatly appreciated. My server: const WebSocket = require('ws');
const server = new WebSocket.Server({ port: 8000 });
server.on('connection', socket => {
console.log(`socket connected`);
socket.send('who');
socket.on('message', msg => {
console.log(`mesage: ${msg}`);
});
socket.on('close', () => {
console.log(`socket closed`);
});
}); Clients: const WebSocket = require('ws');
const directSocket = new WebSocket('http://192.168.2.228:8000');
const proxiedSocket = new WebSocket('http://192.168.2.228:5000/kanatran/proxy');
directSocket.on('open', () => {
console.log('direct socket connection opened');
});
directSocket.on('message', msg => {
if (msg === 'who')
directSocket.send('I am direct');
});
directSocket.on('error', console.log);
proxiedSocket.on('open', () => {
console.log('proxied socket connection opened');
});
proxiedSocket.on('message', msg => {
if (msg === 'who')
proxiedSocket.send('I am proxied');
});
proxiedSocket.on('error', console.log); ASP Proxy route: [Route("proxy")]
public Task Proxy() {
_logger.LogInformation("Proxy request from {RemoteIP}, forwarding", HttpContext.Connection.RemoteIpAddress);
return this.WsProxyAsync("http://192.168.2.228:8000");
} Server output:
Client output:
ASP Proxy output:
|
Alright I think I have this figured out now... First step was to actually enable websockets on the ASP Proxy (add The next thing I found was that I MUST specify My working client now looks like this: const proxiedSocket = new WebSocket('ws://192.168.2.228:5000/kanatran/proxy'); And my ASP Proxy route looked like this: [Route("proxy")]
public Task Proxy() {
_logger.LogInformation("Proxy request from {RemoteIP}, forwarding", HttpContext.Connection.RemoteIpAddress);
return this.WsProxyAsync("ws://192.168.2.228:8000");
} However I now just map it directly in app.UseProxies(proxies => proxies.Map("kanatran/controller", proxy => proxy.UseWs("ws://localhost:8000"))); |
Hi, sorry: just got to this. So, good call out: I can add that to the README. The Microsoft Docs call this out, but I agree that people using this as a WS proxy likely don't look beyond this package. As of now, the proxy uses the Is the non-Startup.cs handler not working? |
Leaving this open until I fix the docs. |
When I was stepping through the decompiled code in the debugger, it looks like you're already doing a check to
No it is working, I just don't need a full controller for the proxy endpoint, so I opted to do it in startup.cs instead of a dedicated controller class. |
I'm trying to proxy twilio comunnication. They have sample in doc how to do that with ngix
Sample configuration:
I'm tried to use AspNetCore.Proxy but I wasn't succeeded.
failed: Error during WebSocket handshake: Unexpected response code: 502
failed: Error during WebSocket handshake: Unexpected response code: 404
How should I setup AspNetCore.Proxy correctly?
The text was updated successfully, but these errors were encountered: