Test_Ctx_IP_ProxyHeader_With_IP_Validation() — fiber Function Reference
Architecture documentation for the Test_Ctx_IP_ProxyHeader_With_IP_Validation() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 1ff3bb07_0d60_692d_a356_5e90a76ae4db["Test_Ctx_IP_ProxyHeader_With_IP_Validation()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] 1ff3bb07_0d60_692d_a356_5e90a76ae4db -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style 1ff3bb07_0d60_692d_a356_5e90a76ae4db fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 2902–2941
func Test_Ctx_IP_ProxyHeader_With_IP_Validation(t *testing.T) {
t.Parallel()
// make sure that the same behavior exists for different proxy header names
proxyHeaderNames := []string{"Real-Ip", HeaderXForwardedFor}
for _, proxyHeaderName := range proxyHeaderNames {
app := New(Config{
EnableIPValidation: true,
ProxyHeader: proxyHeaderName,
TrustProxy: true,
TrustProxyConfig: TrustProxyConfig{
Proxies: []string{"0.0.0.0"},
},
})
fastCtx := &fasthttp.RequestCtx{}
fastCtx.SetRemoteAddr(net.Addr(&net.TCPAddr{IP: net.ParseIP("0.0.0.0")}))
c := app.AcquireCtx(fastCtx)
// when proxy header & validation is enabled and the value is a valid IP, we return it
c.Request().Header.Set(proxyHeaderName, "0.0.0.1")
require.Equal(t, "0.0.0.1", c.IP())
// when proxy header & validation is enabled and the value is a list of IPs, we return the first valid IP
c.Request().Header.Set(proxyHeaderName, "0.0.0.1, 0.0.0.2")
require.Equal(t, "0.0.0.1", c.IP())
c.Request().Header.Set(proxyHeaderName, "invalid, 0.0.0.2, 0.0.0.3")
require.Equal(t, "0.0.0.2", c.IP())
// when proxy header & validation is enabled but the value is empty, we will ignore the header
c.Request().Header.Set(proxyHeaderName, "")
require.Equal(t, "0.0.0.0", c.IP())
// when proxy header & validation is enabled but the value is not an IP, we will ignore the header
// and return the IP of the caller
c.Request().Header.Set(proxyHeaderName, "not-valid-ip")
require.Equal(t, "0.0.0.0", c.IP())
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Ctx_IP_ProxyHeader_With_IP_Validation() do?
Test_Ctx_IP_ProxyHeader_With_IP_Validation() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_IP_ProxyHeader_With_IP_Validation() defined?
Test_Ctx_IP_ProxyHeader_With_IP_Validation() is defined in ctx_test.go at line 2902.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free