Hi, it's me again.
So now I'm using QTcpServer. For every new connection, I use a QHttp to send request, and write the response back to the socket (please tell me if this is stupid; I just thought it would be easier to apply filter).
Everything works fine, except for the Transfer-Encoding: chunked response. All browsers will immediately close the socket after one chunk and act as "page can not be displayed".
I googled and wiki-ed the definition of chunked encoding, did some test, and finally found out that what QHttp::readAll() return is no longer chunked.
Then I tried removing the Transfer-Encoding header before writing. That works, but leads to another problem: by the definition of chunked encoding, the message-sender is allowed to "append" headers after the message body (so-called "trailer"). So if I remove the Transfer-Encoding header, the trailer will be lost (or treated as improper message, depending on how QHttp handle; I haven't tested that yet).
I can re-chunk the message by "repair"ing the size-line of each chunk, but still, I'll have to determine where's the trailer part and avoid counting their length. Since the size-line is already removed by QHttp, I can't think of anything except the colon and space as the identifier of trailer. But there's always chance that the message body contains a colon and space.
So can anyone please tell me how to deal with the chunked encoding transfer? Many thanks.
Bookmarks