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,11 +1,17 @@
package middlewares
import (
"context"
"net/http"
)
// ReplacedPathHeader is the default header to set the old path to
const ReplacedPathHeader = "X-Replaced-Path"
const (
// ReplacePathKey is the key within the request context used to
// store the replaced path
ReplacePathKey key = "ReplacePath"
// ReplacedPathHeader is the default header to set the old path to
ReplacedPathHeader = "X-Replaced-Path"
)
// ReplacePath is a middleware used to replace the path of a URL request
type ReplacePath struct {
@ -14,6 +20,7 @@ type ReplacePath struct {
}
func (s *ReplacePath) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(context.WithValue(r.Context(), ReplacePathKey, r.URL.Path))
r.Header.Add(ReplacedPathHeader, r.URL.Path)
r.URL.Path = s.Path
r.RequestURI = r.URL.RequestURI()