FAQ

Search Discussions

  • Bradfitz at Nov 30, 2012 at 12:36 am
    Reviewers: golang-dev_googlegroups.com,

    Message:
    Hello golang-dev@googlegroups.com,

    I'd like you to review this change to
    https://code.google.com/p/go


    Description:
    net/http: don't send chunked encoding on 204 responses

    RFC 2616: "The 204 response MUST NOT include a message-body,
    and thus is always terminated by the first empty line after
    the header fields."

    Previously we'd trigger chunked encoding by default on
    responses, and then when finishing the request we'd write the
    chunk trailers, which counted as a message-body.

    Fixes issue 4454

    Please review this at https://codereview.appspot.com/6782139/

    Affected files:
    M src/pkg/net/http/server.go
    M src/pkg/net/http/transport_test.go


    Index: src/pkg/net/http/server.go
    ===================================================================
    --- a/src/pkg/net/http/server.go
    +++ b/src/pkg/net/http/server.go
    @@ -369,6 +369,8 @@

    if w.req.Method == "HEAD" || code == StatusNotModified {
    // do nothing
    + } else if code == StatusNoContent {
    + w.header.Del("Transfer-Encoding")
    } else if hasCL {
    w.contentLength = contentLength
    w.header.Del("Transfer-Encoding")
    Index: src/pkg/net/http/transport_test.go
    ===================================================================
    --- a/src/pkg/net/http/transport_test.go
    +++ b/src/pkg/net/http/transport_test.go
    @@ -857,6 +857,30 @@
    }
    }

    +// From http://golang.org/issue/4454 ,
    +// "client fails to handle requests with no body and chunked encoding"
    +func TestChunkedNoContent(t *testing.T) {
    + ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
    + w.WriteHeader(StatusNoContent)
    + }))
    + defer ts.Close()
    +
    + for _, closeBody := range []bool{true, false} {
    + c := &Client{Transport: &Transport{}}
    + const n = 4
    + for i := 1; i <= n; i++ {
    + res, err := c.Get(ts.URL)
    + if err != nil {
    + t.Errorf("closingBody=%v, req %d/%d: %v", closeBody, i, n, err)
    + } else {
    + if closeBody {
    + res.Body.Close()
    + }
    + }
    + }
    + }
    +}
    +
    func TestTransportConcurrency(t *testing.T) {
    const maxProcs = 16
    const numReqs = 500
  • Bradfitz at Nov 30, 2012 at 2:01 am
    *** Submitted as
    https://code.google.com/p/go/source/detail?r=86eed47f9b5c ***

    net/http: don't send chunked encoding on 204 responses

    RFC 2616: "The 204 response MUST NOT include a message-body,
    and thus is always terminated by the first empty line after
    the header fields."

    Previously we'd trigger chunked encoding by default on
    responses, and then when finishing the request we'd write the
    chunk trailers, which counted as a message-body.

    Fixes issue 4454

    R=golang-dev
    CC=golang-dev
    https://codereview.appspot.com/6782139


    https://codereview.appspot.com/6782139/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 30, '12 at 12:34a
activeNov 30, '12 at 2:01a
posts3
users2
websitegolang.org

2 users in discussion

Bradfitz: 2 posts David Symonds: 1 post

People

Translate

site design / logo © 2022 Grokbase