mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Changes regarding review
Use path.Join and then check if the request had a slash at the end to place it again.
This commit is contained in:
parent
eea68c34ad
commit
d9ebc5398a
1 changed files with 6 additions and 4 deletions
|
@ -7,7 +7,8 @@ import (
|
||||||
"html"
|
"html"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
@ -27,9 +28,10 @@ func (rd Redirect) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
newPath := toURL.Host + toURL.Path + r.URL.Path
|
newPath := path.Join(toURL.Host, toURL.Path, r.URL.Path)
|
||||||
rmSlashs := regexp.MustCompile("//+")
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
newPath = rmSlashs.ReplaceAllString(newPath, "/")
|
newPath = newPath + "/"
|
||||||
|
}
|
||||||
newPath = toURL.Scheme + "://" + newPath
|
newPath = toURL.Scheme + "://" + newPath
|
||||||
parameters := toURL.Query()
|
parameters := toURL.Query()
|
||||||
for k, v := range r.URL.Query() {
|
for k, v := range r.URL.Query() {
|
||||||
|
|
Loading…
Reference in a new issue