Skip to content

net/http: make Transport.roundTrip close body on invalid method #35014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

bored-engineer
Copy link
Contributor

@bored-engineer bored-engineer commented Oct 20, 2019

Updates #35015

Fixes a bug where request bodies are not closed when an invalid method name is provided
@googlebot googlebot added the cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label Oct 20, 2019
@bored-engineer bored-engineer changed the title Ensure request body is closed when method is invalid net/http: ensure request body is closed when method is invalid Oct 20, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: b1898d2) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/202237 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Brad Fitzpatrick:

Patch Set 1:

Please fix the commit message and add a test.


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 1:

(1 comment)

Thank you for catching this, Luke and welcome to the Go project!

I've added a suggestion for the commit message but also please add this test to the bottom
of transport_test.go

type bodyCloser bool

func (bc *bodyCloser) Close() error {
*bc = true
return nil
}

func (bc *bodyCloser) Read(b []byte) (n int, err error) {
return 0, io.EOF
}

func TestInvalidMethodClosesBody(t *testing.T) {
cst := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
defer cst.Close()
var bc bodyCloser

    u, _ := url.Parse(cst.URL)
    req := &http.Request{
            Method: " ",
            URL:    u,
            Body:   &bc,
    }

    _, err := http.DefaultClient.Do(req)
    if err == nil {
            t.Fatal("Expected an error")
    }
    if !bc {
            t.Fatal("Expected body to have been closed")
    }

}


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 1: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 1:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=88a6ca4f


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 1: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 4bfc56e) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/202237 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@bored-engineer bored-engineer changed the title net/http: ensure request body is closed when method is invalid net/http: make Transport.roundTrip close body on invalid method Oct 20, 2019
@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 5: Run-TryBot+1 Code-Review+2


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=d6acfb6c


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/202237.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Oct 20, 2019
Updates #35015

Change-Id: Ibfe8f72ed3887ca88ce9c1d8a29dacda72f3fe17
GitHub-Last-Rev: 4bfc56e
GitHub-Pull-Request: #35014
Reviewed-on: https://go-review.googlesource.com/c/go/+/202237
Reviewed-by: Emmanuel Odeke <[email protected]>
Run-TryBot: Emmanuel Odeke <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/202237 has been merged.

@gopherbot gopherbot closed this Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants