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: Server can't use URIEncoded parameters because server redirects (301) #9470

Closed
azr opened this issue Dec 30, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@azr
Copy link

commented Dec 30, 2014

Hello there,

I'm not sure if this is a bug but with the following code :

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":9999", nil)
    return
}

If I curl it with an url that is URIEncoded as a query parameter

$ curl -i "http://localhost:9999/http%3A%2F%2F0.media.dorkly.cvcdn.com%2F36%2F35%2F6603dc5a9292104b44c349b85b5aaf7a-5-crazy-fan-theories-that-make-total-sense.jpg"
HTTP/1.1 301 Moved Permanently
Location: /http:/0.media.dorkly.cvcdn.com/36/35/6603dc5a9292104b44c349b85b5aaf7a-5-crazy-fan-theories-that-make-total-sense.jpg
Date: Tue, 30 Dec 2014 11:28:01 GMT
Content-Length: 152
Content-Type: text/html; charset=utf-8

<a href="/http:/0.media.dorkly.cvcdn.com/36/35/6603dc5a9292104b44c349b85b5aaf7a-5-crazy-fan-theories-that-make-total-sense.jpg">Moved Permanently</a>.

And if I follow the redirect, the url parameters will be

0: http:
1: 0.media.dorkly.cvcdn.com
...
4: 6603dc5a9292104b44c349b85b5aaf7a-5-crazy-fan-theories-that-make-total-sense.jpg

But if I do

$ curl -i "http://localhost:9999/nope?bar=http%3A%2F%2F0.media.dorkly.cvcdn.com%2F36%2F35%2F6603dc5a9292104b44c349b85b5aaf7a-5-crazy-fan-theories-that-make-total-sense.jpg"
HTTP/1.1 200 OK
Date: Tue, 30 Dec 2014 11:35:17 GMT
Content-Length: 21
Content-Type: text/plain; charset=utf-8

Hi there, I love nope!
$ go version
go version go1.4 darwin/amd64

This would be a common nginx pattern for example.
For this I assumed net/http would let the user make the choice between redirecting/using it as a parameter.

Cheers !

@azr azr changed the title net/http.Server: Can't use URIEncoded parameters as server redirects (301) net/http.Server: Can't use URIEncoded parameters because server redirects (301) Dec 30, 2014

@bradfitz

This comment has been minimized.

Copy link
Member

commented Dec 30, 2014

The Go standard library is a bit aggressive with over-unescaping things and for compatibility reasons can't really be "fixed". If you need the raw request, use net/http.Request.RequestURI.

@bradfitz bradfitz closed this Dec 30, 2014

@mikioh mikioh changed the title net/http.Server: Can't use URIEncoded parameters because server redirects (301) net/http: Server can't use URIEncoded parameters because server redirects (301) Dec 31, 2014

@azr

This comment has been minimized.

Copy link
Author

commented Dec 31, 2014

Well, every language have to have something that smells :)
Thanks for the answer !
Happy end of 2014 !! o/

@golang golang locked and limited conversation to collaborators Jun 24, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.