Skip to content
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

net/http: NewRequest cannot handle %2F in path #5777

Closed
gopherbot opened this issue Jun 25, 2013 · 3 comments
Closed

net/http: NewRequest cannot handle %2F in path #5777

gopherbot opened this issue Jun 25, 2013 · 3 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by rjohnson.id.au:

What steps will reproduce the problem?

    urlStr := "http://myhost.com/test%2Fasdf/";
    req, _ = http.NewRequest("GET", urlStr, nil)
    client := new(http.Client)
    resp, err := client.Do(req)


What is the expected output?

    A request to "http://myhost.com/test%2Fasdf/";

What do you see instead?

    A request to "http://myhost.com/test/asdf/";

Which compiler are you using (5g, 6g, 8g, gccgo)?

    N/A, but 6g


Please provide any additional information below.


Unfortunately it appears that http.NewRequest uses url.Parse, which suffers from this
issue: https://golang.org/issue/3659

I would not have added an additional bug, however the original bug seems to have been
closed with the status "Fixed" due to the documentation being updated to
reflect this.  Clearly this is not the correct fix for the issue.
@minux
Copy link
Member

minux commented Jun 25, 2013

Comment 1:

as documented in revision bb293c428338 (issue #3659), you can modify
req.URL.Opaque to achieve your goal.

Status changed to Unfortunate.

@gopherbot
Copy link
Contributor Author

Comment 2 by rjohnson.id.au:

I've gone with:
req, _ = http.NewRequest(verb, reqAddress, buf)
path := strings.TrimPrefix(req.URL.Scheme, reqAddress)
path = strings.Split(reqAddress, "?")[0]
req.URL.Opaque = path
Which is essentially re-parsing the path out.
I feel that if URL.Parse is not to be updated, than http.Request should probably do
something like this?  This issue would present itself again without a workaround if
there were a %2F in a redirect for example.

@rsc
Copy link
Contributor

rsc commented Jun 19, 2015

I see more and more REST services that use %2F in path elements that correspond to variables, and therefore more and more reports like this one. I am reopening this for a possible fix in the Go 1.5 cycle. I have a fix in mind.

@rsc rsc self-assigned this Jun 19, 2015
@rsc rsc reopened this Jun 19, 2015
@mikioh mikioh changed the title net/http.NewRequest cannot handle %2F in path net/http: NewRequest cannot handle %2F in path Jun 19, 2015
@rsc rsc closed this as completed in 874a605 Jun 22, 2015
@mikioh mikioh added this to the Go1.5 milestone Jun 22, 2015
@mikioh mikioh removed the Go1.5Maybe label Jun 22, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants