Closed
Description
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 !