the_velour_fog
the_velour_fog

Reputation: 2184

How does HTTP specify the end of a response for Transfer-encoding: chunked?

From this wikipedia example a typical HTTP response may look like this

HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Content-Type: text/html; charset=UTF-8
Content-Encoding: UTF-8
Content-Length: 138
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
ETag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Connection: close

<html>
<head>
  <title>An Example Page</title>
</head>
<body>
  Hello World, this is a very simple HTML document.
</body>
</html>

In this case because of this header:

Connection: close

the client will know that the HTTP body has finished, because the TCP connection will be closed, Say for example Connection: close wasn't present, the client would still know the HTTP body was finished because this header:

Content-Length: 138

Is saying, once you get 138 bytes, we're done here. But in the case where neither of these headers are used and instead the server sends Transfer-encoding: chunked how does a browser know when a response has completed, so that it can move onto other things?

Upvotes: 1

Views: 2081

Answers (1)

Maria Ines Parnisari
Maria Ines Parnisari

Reputation: 17496

From Wikipedia:

The chunked keyword in the Transfer-Encoding header is used to indicate chunked transfer. Each chunk is preceded by its size. The transmission ends when a zero-length chunk is encountered.

Upvotes: 2

Related Questions