Skip to content
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

WebSockets not forwarded #2006

Open
Mis1eader-dev opened this issue Apr 18, 2024 · 2 comments
Open

WebSockets not forwarded #2006

Mis1eader-dev opened this issue Apr 18, 2024 · 2 comments

Comments

@Mis1eader-dev
Copy link
Member

Mis1eader-dev commented Apr 18, 2024

Describe the bug
Using drogon::app().forward(...) to forward WebSockets does not work.
Tried by having it forward with "http://..." prefix as host, and it is able to establish a WebSocket connection, but can't maintain the connection or send/receive messages, it ends up disconnecting with this logged in the terminal on the forwarder's side:

20240418 14:04:08.810934 UTC 178355 ERROR More responses than expected! - HttpClientImpl.cc:616

As for the receiver, it only gets the new WebSocket connection established, and nothing else after that point.

Also tried forwarding with "ws://..." prefix as host, and it is unable to establish any WebSocket connections.

To Reproduce
Steps to reproduce the behavior:

  1. Create a server with a WebSocket endpoint /ws, listening on port 9090.
  2. Create another server with a preRoutingAdvice that forwards to "http://127.0.0.1:9090", and itself listening on port 8080
  3. Make a WebSocket connection request to ws://127.0.0.1:8080/ws
  4. Observe its behavior

Expected behavior
WebSockets should forward.

Desktop:

  • OS: Ubuntu

Additional context
On a production server it is unable to connect at all.

@Mis1eader-dev
Copy link
Member Author

In case others are looking to create a reverse proxy with WebSockets, use nginx in the meantime until this is resolved.

This is the nginx configuration you can use for inspiration:

server {
	listen 80;
	listen [::]:80;
	location / {
		proxy_pass http://127.0.0.1:9090;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $http_connection;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_cache_bypass $http_upgrade;
	}
}

Change the proxy_pass to whatever your actual backend is listening on.
And of course use https instead of http in production.

@Baxulio
Copy link

Baxulio commented May 6, 2024

Hi dear colleges, this is really needed functionality, can anyone please add this feature? (i tried, but it's a little difficult for me)

Currently we have more than 100 devices and they are in our VPN. we need to connect them via websocket from one domain name. none of the proxy servers is applicable for our use case or requre certificate. Let'sencrypt also has limit of 50 certificates. wildcards also require 3rd party paid organizations, like cloudflare etc.

If this functionality existed in drogon, One could just orchestrate requests and proxy them dynamically to the endpoint needed.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants