diff --git a/ctx_interface_gen.go b/ctx_interface_gen.go index bd060f10d9d..413563e839f 100644 --- a/ctx_interface_gen.go +++ b/ctx_interface_gen.go @@ -374,7 +374,7 @@ type Ctx interface { // If Config.TrustProxy false, it returns false. // IsProxyTrusted can check remote ip by proxy ranges and ip map. IsProxyTrusted() bool - // IsFromLocal will return true if request came from local. + // IsFromLocal will return true if request came from a loopback IP. IsFromLocal() bool // IsFromUnixSocket returns true if the request arrived over a Unix domain socket. IsFromUnixSocket() bool diff --git a/ctx_test.go b/ctx_test.go index 23c6fd26ae8..2d465d48609 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -260,6 +260,31 @@ func Test_Ctx_HeaderHelpers(t *testing.T) { require.False(t, c.HasHeader("X-Trace-Id")) } +// go test -run Test_Ctx_FullURL_DoesNotAliasPooledBuffer +func Test_Ctx_FullURL_DoesNotAliasPooledBuffer(t *testing.T) { + t.Parallel() + + const bufferPoolReuseAttempts = 128 + + app := New() + c := app.AcquireCtx(&fasthttp.RequestCtx{}) + + c.Request().Header.SetHost("example.com") + c.Request().SetRequestURI("/search?q=fiber") + + fullURL := c.FullURL() + require.Equal(t, "http://example.com/search?q=fiber", fullURL) + + for range bufferPoolReuseAttempts { + buf := bytebufferpool.Get() + buf.Reset() + buf.WriteString("https://mutated.example/rewritten") + bytebufferpool.Put(buf) + } + + require.Equal(t, "http://example.com/search?q=fiber", fullURL) +} + // go test -run Test_Ctx_TypedParsingDefaults func Test_Ctx_TypedParsingDefaults(t *testing.T) { t.Parallel() diff --git a/req.go b/req.go index f01d38093da..d714b11a6a0 100644 --- a/req.go +++ b/req.go @@ -215,7 +215,7 @@ func (c *DefaultCtx) FullURL() string { buf.WriteString(c.Host()) buf.WriteString(c.OriginalURL()) - return c.app.toString(buf.Bytes()) + return buf.String() } // UserAgent returns the User-Agent request header. diff --git a/req_interface_gen.go b/req_interface_gen.go index 828d0e9a54c..ee6e646a69e 100644 --- a/req_interface_gen.go +++ b/req_interface_gen.go @@ -185,7 +185,7 @@ type Req interface { // If Config.TrustProxy false, it returns false. // IsProxyTrusted can check remote ip by proxy ranges and ip map. IsProxyTrusted() bool - // IsFromLocal will return true if request came from local. + // IsFromLocal will return true if request came from a loopback IP. IsFromLocal() bool // IsFromUnixSocket returns true if the request arrived over a Unix domain socket. IsFromUnixSocket() bool