Added support for replacement containing escaped characters
Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
This commit is contained in:
parent
a7495f711b
commit
353bd3d06f
4 changed files with 180 additions and 46 deletions
|
@ -3,6 +3,7 @@ package replacepath
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/v2/pkg/log"
|
||||
|
@ -40,8 +41,22 @@ func (r *replacePath) GetTracingInformation() (string, ext.SpanKindEnum) {
|
|||
}
|
||||
|
||||
func (r *replacePath) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
req.Header.Add(ReplacedPathHeader, req.URL.Path)
|
||||
req.URL.Path = r.path
|
||||
if req.URL.RawPath == "" {
|
||||
req.Header.Add(ReplacedPathHeader, req.URL.Path)
|
||||
} else {
|
||||
req.Header.Add(ReplacedPathHeader, req.URL.RawPath)
|
||||
}
|
||||
|
||||
req.URL.RawPath = r.path
|
||||
|
||||
var err error
|
||||
req.URL.Path, err = url.PathUnescape(req.URL.RawPath)
|
||||
if err != nil {
|
||||
log.FromContext(middlewares.GetLoggerCtx(context.Background(), r.name, typeName)).Error(err)
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
req.RequestURI = req.URL.RequestURI()
|
||||
|
||||
r.next.ServeHTTP(rw, req)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue