Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1241)

Issue 4628063: code review 4628063: http: better handling of 0-length Request.Body (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 9 months ago by bradfitz
Modified:
13 years, 9 months ago
Reviewers:
CC:
golang-dev, kevlar
Visibility:
Public.

Description

http: better handling of 0-length Request.Body As rsc suggested after change 58a6bdac3d12 was committed, we now read the first byte of Request.Body when the Request.ContentLength is 0 to disambiguate between a truly zero-length body and a body of unknown length where the user didn't set the ContentLength field. This was also causing the reverse proxy problem where incoming requests (which always have a body, of private type http.body, even for 0-lengthed requests) were being relayed to the http Transport for fetching, which was serializing the request as a chunked request (since ContentLength was 0 and Body was non-nil) Fixes issue 1999

Patch Set 1 #

Patch Set 2 : diff -r 90f9c658e53d https://go.googlecode.com/hg #

Patch Set 3 : diff -r 90f9c658e53d https://go.googlecode.com/hg #

Total comments: 2

Patch Set 4 : diff -r 90f9c658e53d https://go.googlecode.com/hg #

Unified diffs Side-by-side diffs Delta from patch set Stats (+114 lines, -46 lines) Patch
M src/pkg/http/request.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/http/requestwrite_test.go View 1 7 chunks +84 lines, -35 lines 0 comments Download
M src/pkg/http/reverseproxy_test.go View 1 1 chunk +3 lines, -0 lines 0 comments Download
M src/pkg/http/transfer.go View 1 4 chunks +27 lines, -4 lines 0 comments Download

Messages

Total messages: 4
bradfitz
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg
13 years, 9 months ago (2011-06-24 22:26:00 UTC) #1
kevlar
LGTM http://codereview.appspot.com/4628063/diff/2005/src/pkg/http/transfer.go File src/pkg/http/transfer.go (right): http://codereview.appspot.com/4628063/diff/2005/src/pkg/http/transfer.go#newcode55 src/pkg/http/transfer.go:55: t.Body = io.MultiReader(bytes.NewBuffer(buf[:]), t.Body) I assume, based on ...
13 years, 9 months ago (2011-06-24 23:19:44 UTC) #2
bradfitz
http://codereview.appspot.com/4628063/diff/2005/src/pkg/http/transfer.go File src/pkg/http/transfer.go (right): http://codereview.appspot.com/4628063/diff/2005/src/pkg/http/transfer.go#newcode55 src/pkg/http/transfer.go:55: t.Body = io.MultiReader(bytes.NewBuffer(buf[:]), t.Body) On 2011/06/24 23:19:45, kevlar wrote: ...
13 years, 9 months ago (2011-06-24 23:25:43 UTC) #3
bradfitz
13 years, 9 months ago (2011-06-24 23:46:23 UTC) #4
*** Submitted as http://code.google.com/p/go/source/detail?r=59f3e8fcb8da ***

http: better handling of 0-length Request.Body

As rsc suggested after change 58a6bdac3d12 was committed, we
now read the first byte of Request.Body when the
Request.ContentLength is 0 to disambiguate between a truly
zero-length body and a body of unknown length where the user
didn't set the ContentLength field.

This was also causing the reverse proxy problem where incoming
requests (which always have a body, of private type http.body,
even for 0-lengthed requests) were being relayed to the http
Transport for fetching, which was serializing the request as a
chunked request (since ContentLength was 0 and Body was
non-nil)

Fixes issue 1999

R=golang-dev, kevlar
CC=golang-dev
http://codereview.appspot.com/4628063
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b