[http] empty POST and PUT requests

2,786 views
Skip to first unread message

Dave Grijalva

unread,
Sep 1, 2011, 9:41:05 PM9/1/11
to golang-nuts
I'm not sure what the specification says, but many popular http
servers (including nginx) expect ALL PUT and POST requests to have a
specified Content-Length, even if there is no message body. If you
try to write an http.Request with no body, it appears to be impossible
to include a content-length header for a nil or zero-length body.

I've got a patch that fixes this behavior by including the Content-
Length header in all PUT and POST requests. Are people cool with this
change?

Brad Fitzpatrick

unread,
Sep 2, 2011, 1:28:58 AM9/2/11
to Dave Grijalva, golang-nuts
This keeps coming up in different forms.  See server_test.go and requestwrite_test.go.  Search for "empty", "zero", etc.

If the specification is ambiguous (but please research it first) and nginx et al require it, I'm fine including a "Content-Length: 0" when request.ContentLength = 0 (/ unset) and the Request.Body is nil or immediately EOFs (which there's an existing check for, which I think simply omits the Transfer-Encoding: chunked).

So yeah, I'm cool with it, but it'll need tests & docs & references.  These corner cases are gross and annoying when they keep coming up, so I'd like it well tested & documented so we don't regress.

Dave Grijalva

unread,
Sep 2, 2011, 2:58:49 AM9/2/11
to Brad Fitzpatrick, golang-nuts
Totally agree. HTTP in practice is horribly messy. I'll send a bug and patch tomorrow with tests and whatnot. 

-dave

Dave Grijalva

unread,
Sep 2, 2011, 6:09:10 PM9/2/11
to golang-nuts
Gah! The codereview mercurial extension is crashing on Lion for me.
Is there a known issue/fix for this? Otherwise, I can wait until my
snow leopard machine comes back from surgery to submit this fix.


On Sep 1, 11:58 pm, Dave Grijalva <grija...@gmail.com> wrote:
> Totally agree. HTTP in practice is horribly messy. I'll send a bug and patch tomorrow with tests and whatnot.
>
> -dave
>
> On Sep 1, 2011, at 10:28 PM, Brad Fitzpatrick <bradf...@golang.org> wrote:
>
>
>
>
>
>
>
> > This keeps coming up in different forms.  See server_test.go and requestwrite_test.go.  Search for "empty", "zero", etc.
>
> > If the specification is ambiguous (but please research it first) and nginx et al require it, I'm fine including a "Content-Length: 0" when request.ContentLength = 0 (/ unset) and the Request.Body is nil or immediately EOFs (which there's an existing check for, which I think simply omits the Transfer-Encoding: chunked).
>
> > So yeah, I'm cool with it, but it'll need tests & docs & references.  These corner cases are gross and annoying when they keep coming up, so I'd like it well tested & documented so we don't regress.
>

Rob 'Commander' Pike

unread,
Sep 2, 2011, 6:20:36 PM9/2/11
to Dave Grijalva, golang-nuts

On 03/09/2011, at 8:09 AM, Dave Grijalva wrote:

> Gah! The codereview mercurial extension is crashing on Lion for me.
> Is there a known issue/fix for this? Otherwise, I can wait until my
> snow leopard machine comes back from surgery to submit this fix.

Can you give more details?

-rob


Kyle Lemons

unread,
Sep 2, 2011, 6:36:39 PM9/2/11
to Dave Grijalva, golang-nuts
It's broken at release but it is fixed at tip.  Of course, this means you have to disable the codereview plugin (I just commented it out) before switching to tip and re-enabling it.

At least, that was my experience.
~K
Reply all
Reply to author
Forward
0 new messages