-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
v2: Use r.URL.RawPath for rewrite #3596
Comments
Thanks for the issue / suggestion! Usually I think But why do we need this?
Do you have any examples of when this is the case? |
We need this so that we can proxy requests largely unmodified to backends. Here's an example. Note that retrieving the TEST2 value using the same path doesn't work. Caddyfile:
Simple HTTP backend server in Go: package main
import (
"io/ioutil"
"net/http"
"net/url"
)
func main() {
m := make(map[url.URL][]byte)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
println(r.URL.String())
w.Write(m[*r.URL])
if r.Method == http.MethodPut {
if b, err := ioutil.ReadAll(r.Body); err == nil {
m[*r.URL] = b
}
}
})
http.ListenAndServe(":8080", nil)
} Test by making requests to caddy: $ echo TEST1 | curl -XPUT --data-binary @- "localhost/kv/Caddy%20v2%20rulez"
$ curl "localhost/key-value/Caddy%20v2%20rulez"
TEST1
$ echo TEST2 | curl -XPUT --data-binary @- "localhost/kv/Caddy%2Fv2%20rulez!"
$ curl "localhost/key-value/Caddy%2Fv2%20rulez!"
$ curl "localhost/key-value/Caddy/v2%20rulez%21"
TEST2 |
Hmmm my senses are tingling and I think it's because your example has a mistake. There is a standardized form of the URL you can use in your server's map ( So there are two places where the behavior is actually buggy (the client for sending a malformed URL) and the Go program for indexing on the un-standardized form of the URL. I am going to close this as I'm pretty convinced we shouldn't make the proposed change (which will probably break a lot of other cases) but feel free to continue discussion if necessary. Thanks! |
I think by standardized you mean decoded. The example deliberately uses URL struct as map key to expose the problem with Caddy's rewrite. Focusing on how this example code would improve by using decoded form misses the point. Namely that URL.Path is lossy. My example does not have a mistake. Encoding encodeURIComponent("Caddy/v2 rulez!")
"Caddy%2Fv2%20rulez!" These URLs aren't semantically equivalent:
Because:
A server must be able to distinguish which one a client has sent, and optionally treat them differently. Passing requests unmangled is currently not possible with
|
Will give this some more consideration. |
When the Go builtin |
Been fiddling with this for a while. Thought the proposed fix made tests fail, but turns out git hadn't applied the whole thing for some reason so I manually verified it before running tests again and now they are passing. @go-d Do you want to submit a PR, and add some test cases to |
Pinging @go-d -- it's too late to put this in v2.3, but I'll add it to the 2.3.1 or 2.4 tree in a couple of weeks (-ish) unless you want to submit a PR to get the credit for it? |
Prevent information loss, i.e. the encoded form that was sent by the client, when using URL strip/replace.
When using e.g.
uri replace
paths get automatically unescaped. This might be undesirable. Something like this would fix it:What do you think? Maybe there's a better way?
The text was updated successfully, but these errors were encountered: