beast: websocket handshake differs from curl output, fails with obscure server
beast version 67
note I have replaced the host with [host] throughout, I can privately share the real host to help testing
I’m using this curl command to handshake with a server based on a pascal websocket server (http://www.esegece.com/websockets/)
curl -v -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: [host]" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" -H "Sec-WebSocket-Version: 13" https://[host]
I am trying to do the same handshake with beast, even copying the curl headers:
beast::websocket::response_type res;
ws.handshake_ex(res, host, "/",
[](beast::websocket::request_type &m)
{
m.insert(beast::http::field::accept, "*/*");
m.insert(beast::http::field::user_agent, "curl/7.47.0");
std::cout << m << std::endl;
},
ec);
std::cout << res << std::endl;
the server accepts the curl connection but rejects the beast connection. the server’s logs show that the headers are received with extra newlines or something like newlines in the case of beast:
server logs for curl connection:
Recv: GET / HTTP/1.1
Host: [host]
User-Agent: curl/7.47.0
Accept: */*
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Sent: HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Server: sgcWebSockets 3.5
server logs for beast:
Recv: GET
Recv: /
Recv: HTTP/1.1
Recv: Host: [host]
Recv: Upgrade: websocket
Recv: Connection: upgrade
Recv: Sec-WebSocket-Key: lD7oPd7/ryIbKDcgimpDAA==
Recv: Sec-WebSocket-Version: 13
Recv: Accept: */*
Recv: User-Agent: curl/7.47.0
Recv:
Sent: HTTP/1.1 302 Moved Temporarily
Connection: close
Content-Length: 0
Date: Tue, 27 Jun 2017 17:01:11 GMT
Server: sgcWebSockets 3.5
Location: login
Set-Cookie: IDHTTPSESSIONID=ANv2nTA6vZ8PuVx; Path=/
I also tested beast using mitmproxy (https://mitmproxy.org/) instead of connecting to the server directly, and it works correctly in this case, as I assume mitmproxy is putting the headers together. I assume my problem has to do with the extra newlines in the beast output. This may be standards-compliant (I don’t know), but it’s making my server unhappy. Is there a way to change this?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 76 (43 by maintainers)
obviously I was not understanding this, haha. that’s good documentation, I’ll fix things and report back
yes, thanks! working sync functions are enough for me for now. I do plan to finish this but my schedule is full till August 23
hey, it works now! I’ll implement the rest of your suggestions and do some cleanup and try tests/async
ha yes I just found the reference. thanks, I will make those changes
absolutely, I have implemented embedded http servers across a whole suite of programs (still need to update using the new framework) and I was able to exorcise curl for simple http GET/POST requests with a short extension/asyncification of the http client example. Had to do async because there’s essentially no support for timeouts in asio sync methods (see this awesome wontfix - https://svn.boost.org/trac10/ticket/2832). so I recommend a note about this somewhere and maybe an async example or a link to some asio async resources. I can try to sanitize /release my extension if that would help
getting rid of curl on an embedded target takes my runtime link dependencies down from 50-something to ~17, it’s crazy. curl is extremely hard to statically link on debian and very much embraces the “unix way” of having tons of small supporting elements. so for a couple GET/POST it gets to be a bit much. most competitive libraries are similarly huge and can be hard to set up
so, anyway, this fills a big void in simple to set up and non-bloated http tools for c++, thank you
no problem at all, I will get to this in a couple hours. Thanks for all the help