HTTP: Fix the socket being closed before all bytes were read by client

We were writing to the QTcpSocket and then calling
waitForBytesWritten() with the assumption that this would only return
once all the written bytes had been read from the socket by the
client. This wasn't actually the case and this could lead to the
socket being closed before the full response was sent.

Now we wait until all pending data has been sent before closing the
socket.