Summer_More_More_Tea
Summer_More_More_Tea

Reputation: 13446

How to configure `Content-Length' header in HTTP protocol

I don't clear about how to count `Content-Length' header in HTTP.

Take an example,

HEADER
...
Content-Type: text/html
(blank line `\r\n')
<html></html>
(blank line `\r\n')

This is a working http request sending an empty HTML page(correct me if any problem :-)). Then what should be the length of content? 15 or 17(take the blank line between header and sending entity into account)?

Thanks in advance. Best regards.

Upvotes: 0

Views: 7024

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 598114

15 is the correct answer. That counts the line break at the END of the entity data, which means that line break is part of the entity, not the http protocol. DO NOT count the line break between the headers and entity.

Upvotes: 2

powtac
powtac

Reputation: 41080

According to W3 Content-Lentgth is defined as followed:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

As far as I understand it, you have to count everything after the first line break. My answer to your question would be 15 then.

Upvotes: 4

Related Questions