Home / Function/ Test_Ctx_IsFromLocal_X_Forwarded() — fiber Function Reference

Test_Ctx_IsFromLocal_X_Forwarded() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

ctx_test.go lines 7719–7761

func Test_Ctx_IsFromLocal_X_Forwarded(t *testing.T) {
	t.Parallel()
	// Test unset X-Forwarded-For header.
	{
		app := New()
		c := app.AcquireCtx(&fasthttp.RequestCtx{})
		// fasthttp returns "0.0.0.0" as IP as there is no remote address.
		require.Equal(t, "0.0.0.0", c.IP())
		require.False(t, c.IsFromLocal())
	}
	// Test when setting X-Forwarded-For header to localhost "127.0.0.1"
	{
		app := New()
		c := app.AcquireCtx(&fasthttp.RequestCtx{})
		c.Request().Header.Set(HeaderXForwardedFor, "127.0.0.1")
		defer app.ReleaseCtx(c)
		require.False(t, c.IsFromLocal())
	}
	// Test when setting X-Forwarded-For header to localhost "::1"
	{
		app := New()
		c := app.AcquireCtx(&fasthttp.RequestCtx{})
		c.Request().Header.Set(HeaderXForwardedFor, "::1")
		defer app.ReleaseCtx(c)
		require.False(t, c.IsFromLocal())
	}
	// Test when setting X-Forwarded-For to full localhost IPv6 address "0:0:0:0:0:0:0:1"
	{
		app := New()
		c := app.AcquireCtx(&fasthttp.RequestCtx{})
		c.Request().Header.Set(HeaderXForwardedFor, "0:0:0:0:0:0:0:1")
		defer app.ReleaseCtx(c)
		require.False(t, c.IsFromLocal())
	}
	// Test for a random IP address.
	{
		app := New()
		c := app.AcquireCtx(&fasthttp.RequestCtx{})
		c.Request().Header.Set(HeaderXForwardedFor, "93.46.8.90")

		require.False(t, c.Req().IsFromLocal())
	}
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free