QWebSocketServer: Fix quadratic copy and scan during pre-handshake
WebSockets is built on the back of HTTP and, as such, needs to deal with
a little bit of HTTP when getting started.
Over the years this code evolved a bit at a time to become more
resilient to various splits and such, and eventually ended up at its
current state. This, however, is quite slow when a client needs multiple
packets to transfer their HTTP header to start the connection and
resulted in needless re-scanning of already-scanned header fields.
Fix it by storing the header as it comes in and only scanning the new
segments. The header is already size-limited on the server, and transfer
is bounded by a timer, and would anyway be in memory already, this is
just moving where the buffer is.
[ChangeLog][QWebSocketServer] The handshake header size limit is now
applied as the request arrives, rather than only while the end of the
headers has not been seen. An over-sized request now fails with
QWebSocketProtocol::CloseCodeTooMuchData and "Header is too large."
instead of CloseCodeProtocolError and "Invalid handshake request."
Pick-to: 6.12 6.12.0 6.11 6.11.3 6.8 6.5 5.15
Task-number: QTBUG-150324
Change-Id: If4a3de31dddf3ea6e4dd61ce2d685a88164b18e7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>