valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.87k stars 1.76k forks source link

make normalizePath() remove only the initial double slash #1592

Closed 4W closed 1 year ago

4W commented 1 year ago

The current normalizePath function in uri.go removes all double slashes, for example:

    req.SetRequestURI("https://example.com/api//test")
    var resp *fasthttp.Response = fasthttp.AcquireResponse()
    httpClient.Do(req, resp)
    ... 

The code above will send a request to https://example.com/api/test and not https://example.com/api//test

The normalizePath is called through several other functions, but it is called regardless when sending a request, which makes it unavoidable. Currently the only practical use for normalizePath is removing the INITIAL double slash, if https://example.com/api//test is the set URI, the URI will turn into https://example.com//api//test thereafter normalizePath is called and removes all double slashes, though it should only be removing the first.

In rare cases you will have to access URLs utilizing double slashes, and you cannot do that with this library at the moment. So I think it would be best if this was either removed, or modified in a certain way so you can keep certain double slashes.

erikdubbelboer commented 1 year ago

What you are looking for is: https://pkg.go.dev/github.com/valyala/fasthttp#Client.DisablePathNormalizing