fix: use EscapedPath as header value when RawPath is empty
This commit is contained in:
parent
25e12aee14
commit
fe32a7e584
4 changed files with 28 additions and 13 deletions
|
@ -16,9 +16,7 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/tracing"
|
||||
)
|
||||
|
||||
const (
|
||||
typeName = "ReplacePathRegex"
|
||||
)
|
||||
const typeName = "ReplacePathRegex"
|
||||
|
||||
// ReplacePathRegex is a middleware used to replace the path of a URL request with a regular expression.
|
||||
type replacePathRegex struct {
|
||||
|
@ -50,16 +48,13 @@ func (rp *replacePathRegex) GetTracingInformation() (string, ext.SpanKindEnum) {
|
|||
}
|
||||
|
||||
func (rp *replacePathRegex) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
var currentPath string
|
||||
if req.URL.RawPath == "" {
|
||||
currentPath = req.URL.Path
|
||||
} else {
|
||||
currentPath = req.URL.RawPath
|
||||
currentPath := req.URL.RawPath
|
||||
if currentPath == "" {
|
||||
currentPath = req.URL.EscapedPath()
|
||||
}
|
||||
|
||||
if rp.regexp != nil && len(rp.replacement) > 0 && rp.regexp.MatchString(currentPath) {
|
||||
req.Header.Add(replacepath.ReplacedPathHeader, currentPath)
|
||||
|
||||
req.URL.RawPath = rp.regexp.ReplaceAllString(currentPath, rp.replacement)
|
||||
|
||||
// as replacement can introduce escaped characters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue