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

Adding port to host in WebSocketHandshake::clientHandshake causes HTTP/1.1 404 Not Found #521

Open
ArthurChristianus opened this issue Jun 21, 2024 · 1 comment

Comments

@ArthurChristianus
Copy link

Hi!
First of all, I would like to thank you for the effort you put in creating this library. The ease of use and clean syntax makes it great to work with.

I am trying to create a websocket connection to a server. However, when adding the port to the host in the initial handshake message, the server returns HTTP/1.1 404 Not Found.

E.g. This can connect to the server:

ss << "GET " << path << " HTTP/1.1\r\n";
ss << "Host: " << host << "\r\n";
ss << "Upgrade: websocket\r\n";

And this cannot:

ss << "GET " << path << " HTTP/1.1\r\n";
ss << "Host: " << host << ":" << port << "\r\n";
ss << "Upgrade: websocket\r\n";

I am completely new to websockets so I am unsure if this is a problem with IXWidgets. If it is, I am more than willing to create a pull request to fix this.

@bsergean
Copy link
Collaborator

Hi @ArthurChristianus, thanks for the good words.

I'm surprised that ports aren't working ... we've been using that since forever. Are you using SSL, or SNI ?

Can you see the same problem when you build the builtin ws client (you can run a test server, and a test client).

Here I set the host to ws://localhost:8008

$ ./ws/ws connect ws://localhost:8008
Type Ctrl-D to exit prompt...
Connecting to url: ws://localhost:8008
> [2024-07-23 16:18:57.520] [info] ws_connect: connected
[2024-07-23 16:18:57.521] [info] Uri: /
[2024-07-23 16:18:57.521] [info] Headers:
[2024-07-23 16:18:57.521] [info] Connection: Upgrade
[2024-07-23 16:18:57.521] [info] Sec-WebSocket-Accept: +Bv6//Th2IRsDfBXKW0vl6AXckM=
[2024-07-23 16:18:57.521] [info] Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15
[2024-07-23 16:18:57.521] [info] Server: ixwebsocket/11.4.6 macos nossl zlib 1.2.12
[2024-07-23 16:18:57.521] [info] Upgrade: websocket
[2024-07-23 16:18:57.521] [info] Received pong ixwebsocket::heartbeat::30s::0
> ECHO !
> [2024-07-23 16:19:10.601] [info] Received 8 bytes
ws_connect: received message: ECHO !

Server

$ ./ws/ws echo_server
[2024-07-23 16:18:26.193] [info] Listening on 127.0.0.1:8008
[2024-07-23 16:18:57.520] [info] New connection
[2024-07-23 16:18:57.520] [info] remote ip: 127.0.0.1
[2024-07-23 16:18:57.520] [info] id: 0
[2024-07-23 16:18:57.520] [info] Uri: /
[2024-07-23 16:18:57.520] [info] Headers:
[2024-07-23 16:18:57.520] [info] Connection: Upgrade
[2024-07-23 16:18:57.520] [info] Host: localhost:8008
[2024-07-23 16:18:57.520] [info] Origin: ws://localhost:8008
[2024-07-23 16:18:57.520] [info] Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15
[2024-07-23 16:18:57.520] [info] Sec-WebSocket-Key: YkZjQzUyRkNEZUNmYjY5Rw==
[2024-07-23 16:18:57.520] [info] Sec-WebSocket-Version: 13
[2024-07-23 16:18:57.520] [info] Upgrade: websocket
[2024-07-23 16:18:57.520] [info] User-Agent: ixwebsocket/11.4.6 macos nossl zlib 1.2.12
[2024-07-23 16:19:10.601] [info] Received 8 bytes

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