diff options
| author | Dmitri Shuralyov <shurcooL@gmail.com> | 2017-02-07 10:57:33 -0500 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-02-08 21:22:27 +0000 |
| commit | af59742d0f6abe96eb5d68151b4d2ccb45d5ed89 (patch) | |
| tree | e301c2b30177a155572c4e6787a573ce4c4982b1 /src/net/http/server.go | |
| parent | a146dd3a2fdf87bab90ee1f636c38cd3444e55fa (diff) | |
| download | go-af59742d0f6abe96eb5d68151b4d2ccb45d5ed89.tar.xz | |
net/http: don't modify Request in StripPrefix
As of https://golang.org/cl/21530, rules are updated to state
that Handlers shouldn't modify the provided Request. This change
updates StripPrefix to follow that rule.
Resolves #18952.
Change-Id: I29bbb580722e871131fa75a97e6e038ec64fdfcd
Reviewed-on: https://go-review.googlesource.com/36483
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index df70a15193..25573d9594 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1973,8 +1973,12 @@ func StripPrefix(prefix string, h Handler) Handler { } return HandlerFunc(func(w ResponseWriter, r *Request) { if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { - r.URL.Path = p - h.ServeHTTP(w, r) + r2 := new(Request) + *r2 = *r + r2.URL = new(url.URL) + *r2.URL = *r.URL + r2.URL.Path = p + h.ServeHTTP(w, r2) } else { NotFound(w, r) } |
