jeffbRTC
jeffbRTC

Reputation: 2069

Why does this HTTP response stream yield a parsing error?

I sent an HTTP response to the socket in segments, but when testing with Postman, Postman fails to parse the response. Postman outputs:

Parse Error: Expected HTTP/

First segment:

HTTP/1.1 200 OK\r\n
Accept-Ranges: bytes\r\n
Content-Type: text/html; charset=UTF-8\r\n
Content-Length: 648\r\n\r\n

Second segment:

<!doctype html>\n
<html>\n
<head>\n
    <title>Example Domain</title>\n 
</head

Third segment:

>\n
<body>\n
<div>\n
    <h1>Example Domain</h1>\n
    <p>This domain is for use in illustrative examples in documents. You may use this\n
    domain in literature without prior coordination or asking for permission.</p>\n
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>\n
</div>\n
</body>\n
</html>\n
\r\n\r\n

I can clearly see all these messages in Wireshark.

The header title in Wireshark is HTTP/1.1 200 OK (text/html)Continuation.

These three segments are classified by Wireshark as follows:

  1. First segment as Hypertext Transfer Protocol
  2. Second segment as Line-based text data: text/html (5 lines)
  3. Third segment as Hypertext Transfer Protocol

Am I streaming these segments correctly? What am I missing here?

A little update:

I attempted to use CURL and it looks like the third segment is not getting thru so I am seeing half of the response in CURL without any errors; the third segment is there according to Wireshark.

Upvotes: 1

Views: 1047

Answers (1)

jeffbRTC
jeffbRTC

Reputation: 2069

I figured out what causing this. It's the content-length. The content-length actually invalid because the response shows gzipped content length instead of actual content-length so I have to re-calculate content length before sending response.

Since content-length is wrong, the parsing fails to digest the response as valid HTML document.

Upvotes: 3

Related Questions