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
|
@ -41,12 +41,12 @@ func (r *replacePath) GetTracingInformation() (string, ext.SpanKindEnum) {
|
|||
}
|
||||
|
||||
func (r *replacePath) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.RawPath == "" {
|
||||
req.Header.Add(ReplacedPathHeader, req.URL.Path)
|
||||
} else {
|
||||
req.Header.Add(ReplacedPathHeader, req.URL.RawPath)
|
||||
currentPath := req.URL.RawPath
|
||||
if currentPath == "" {
|
||||
currentPath = req.URL.EscapedPath()
|
||||
}
|
||||
|
||||
req.Header.Add(ReplacedPathHeader, currentPath)
|
||||
req.URL.RawPath = r.path
|
||||
|
||||
var err error
|
||||
|
|
|
@ -60,6 +60,16 @@ func TestReplacePath(t *testing.T) {
|
|||
expectedRawPath: "/foo%2Fbar",
|
||||
expectedHeader: "/path",
|
||||
},
|
||||
{
|
||||
desc: "replacement with percent encoded backspace char",
|
||||
path: "/path/%08bar",
|
||||
config: dynamic.ReplacePath{
|
||||
Path: "/path/%08bar",
|
||||
},
|
||||
expectedPath: "/path/\bbar",
|
||||
expectedRawPath: "/path/%08bar",
|
||||
expectedHeader: "/path/%08bar",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue