mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: refine trailing-slash redirect logic
Do not add a trailing slash and redirect if the path already ends in a slash. Also, and unrelatedly, add a test for cleanPath. Fixes #65624. Change-Id: Ifcf9edc929d2eb6db88132c09d2bade85c5dda3d Reviewed-on: https://go-review.googlesource.com/c/go/+/562557 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
2a59041420
commit
e17e5308fd
3 changed files with 36 additions and 2 deletions
|
|
@ -2577,8 +2577,8 @@ func (mux *ServeMux) matchOrRedirect(host, method, path string, u *url.URL) (_ *
|
|||
|
||||
n, matches := mux.tree.match(host, method, path)
|
||||
// If we have an exact match, or we were asked not to try trailing-slash redirection,
|
||||
// then we're done.
|
||||
if !exactMatch(n, path) && u != nil {
|
||||
// or the URL already has a trailing slash, then we're done.
|
||||
if !exactMatch(n, path) && u != nil && !strings.HasSuffix(path, "/") {
|
||||
// If there is an exact match with a trailing slash, then redirect.
|
||||
path += "/"
|
||||
n2, _ := mux.tree.match(host, method, path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue