How this GET response Content-Length calculate?

artwl picture artwl · Sep 24, 2013 · Viewed 12.2k times · Source

The Response headers is:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RDpcTkVUXFRlc3RcTXZjQXBwbGljYXRpb25UZXN0XGhvbWVcR2V0VGVzdA==?=
X-Powered-By: ASP.NET
Date: Tue, 24 Sep 2013 02:06:35 GMT
Content-Length: 129

and response is:

This is a get

as picture: enter image description here

enter image description here

i want to know how the Content-Length:129 calculate,thanks!

Answer

HttpWatchSupport picture HttpWatchSupport · Sep 24, 2013

The Content-Length header contains the size of the response body (i.e. the data after the headers) in bytes.

In your example above, gzip compression is used so the 129 bytes indicates that the string "This is a get" required 129 bytes to transmit with gzip compression. Although, compression is intended to reduce payload size it can have the opposite effect for very small content bodies or if the content is already compressed (e.g. images);

http://www.httpwatch.com/httpgallery/compression/

This blog posts explains how content length is handled in HTTP responses:

http://www.httpwatch.com/httpgallery/chunked/