1
0
Fork 0

Extend https redirection tests, and fix incorrect behavior

This commit is contained in:
Daniel Tomcej 2018-08-14 10:38:04 -06:00 committed by Traefiker Bot
parent bd3c8c3cde
commit 870755e90d
7 changed files with 110 additions and 111 deletions

View file

@ -1,6 +1,7 @@
package middlewares
import (
"context"
"net/http"
"regexp"
"strings"
@ -30,6 +31,7 @@ func NewReplacePathRegexHandler(regex string, replacement string, handler http.H
func (s *ReplacePathRegex) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if s.Regexp != nil && len(s.Replacement) > 0 && s.Regexp.MatchString(r.URL.Path) {
r = r.WithContext(context.WithValue(r.Context(), ReplacePathKey, r.URL.Path))
r.Header.Add(ReplacedPathHeader, r.URL.Path)
r.URL.Path = s.Regexp.ReplaceAllString(r.URL.Path, s.Replacement)
r.RequestURI = r.URL.RequestURI()