Home / Function/ Test_Ctx_IP_ProxyHeader() — fiber Function Reference

Test_Ctx_IP_ProxyHeader() — fiber Function Reference

Architecture documentation for the Test_Ctx_IP_ProxyHeader() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  ae305d99_72b8_6a5d_6e06_5f8603167412["Test_Ctx_IP_ProxyHeader()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  ae305d99_72b8_6a5d_6e06_5f8603167412 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style ae305d99_72b8_6a5d_6e06_5f8603167412 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 2862–2899

func Test_Ctx_IP_ProxyHeader(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{
			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)

		c.Request().Header.Set(proxyHeaderName, "0.0.0.1")
		require.Equal(t, "0.0.0.1", c.IP())

		// without IP validation we return the full string
		c.Request().Header.Set(proxyHeaderName, "0.0.0.1, 0.0.0.2")
		require.Equal(t, "0.0.0.1, 0.0.0.2", c.IP())

		// without IP validation we return invalid IPs
		c.Request().Header.Set(proxyHeaderName, "invalid, 0.0.0.2, 0.0.0.3")
		require.Equal(t, "invalid, 0.0.0.2, 0.0.0.3", c.IP())

		// when proxy header is enabled but the value is empty, without IP validation we return an empty string
		c.Request().Header.Set(proxyHeaderName, "")
		require.Empty(t, c.IP())

		// without IP validation we return an invalid IP
		c.Request().Header.Set(proxyHeaderName, "not-valid-ip")
		require.Equal(t, "not-valid-ip", c.IP())
	}
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Ctx_IP_ProxyHeader() do?
Test_Ctx_IP_ProxyHeader() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_IP_ProxyHeader() defined?
Test_Ctx_IP_ProxyHeader() is defined in ctx_test.go at line 2862.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free