Skip to content

[http] Content-Length header should be included for 0 length POST and PUT #2221

@gopherbot

Description

@gopherbot

by grijalva:

What steps will reproduce the problem?
1. r := http.NewRequest("POST", "http://example.com/";, nil)
2. r.Write(something)

What is the expected output?

"Content-Length: 0" header should be included

What do you see instead?

Header is left out

Which revision are you using?  (hg identify)
r.59

Please provide any additional information below.

The specification is not especially clear on this requirement, however several popular
web servers, including nginx will return an error if the content-length is not specified
for a POST or PUT.

RFC2616 (HTTP 1.1) Section 14.13 says:

Applications SHOULD use this field to indicate the transfer-length of the message-body,
unless this is prohibited by the rules in section 4.4.

Any Content-Length greater than or equal to zero is a valid value. Section 4.4 describes
how to determine the length of a message-body if a Content-Length is not given.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions