c++httpboostwebsocketbeast

HTTP Pipelining vs. WebSocket in Boost.Beast advanced server example


I have a question to this Boost.Beast example:

https://github.com/boostorg/beast/blob/908f84cb3c023ed7c5bd19e2e5283d3218a6d820/example/advanced/server/advanced_server.cpp

In line 643 a WebSocket upgrade is done. However, if I understand it correctly, there may still be HTTP write commands in the queue that are asynchronously executed. They are thus executed in parallel to the current WebSocket communication. Is that legal? Or have I not yet fully understood the example?


Solution

  • It is not legal to send an HTTP response after already sending a 101 Switching Protocols response. But that can't happen, because as soon as the server receives an Upgrade HTTP request, it will follow the upgrade procedure. A client who sends another normal HTTP request after sending an Upgrade request would be in error.