Home / Function/ TestContextClientIPWithMultipleHeaders() — gin Function Reference

TestContextClientIPWithMultipleHeaders() — gin Function Reference

Architecture documentation for the TestContextClientIPWithMultipleHeaders() function in context_test.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  f1d869c9_9e3f_e726_e03c_5297b3aa05dc["TestContextClientIPWithMultipleHeaders()"]
  ebe0ae48_a62b_a38f_5bac_5bbbd96fc508["context_test.go"]
  f1d869c9_9e3f_e726_e03c_5297b3aa05dc -->|defined in| ebe0ae48_a62b_a38f_5bac_5bbbd96fc508
  style f1d869c9_9e3f_e726_e03c_5297b3aa05dc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

context_test.go lines 1163–1178

func TestContextClientIPWithMultipleHeaders(t *testing.T) {
	c, _ := CreateTestContext(httptest.NewRecorder())
	c.Request, _ = http.NewRequest(http.MethodGet, "/test", nil)

	// Multiple X-Forwarded-For headers
	c.Request.Header.Add("X-Forwarded-For", "1.2.3.4, "+localhostIP)
	c.Request.Header.Add("X-Forwarded-For", "5.6.7.8")
	c.Request.RemoteAddr = localhostIP + ":1234"

	c.engine.ForwardedByClientIP = true
	c.engine.RemoteIPHeaders = []string{"X-Forwarded-For"}
	_ = c.engine.SetTrustedProxies([]string{localhostIP})

	// Should return 5.6.7.8 (last non-trusted IP)
	assert.Equal(t, "5.6.7.8", c.ClientIP())
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does TestContextClientIPWithMultipleHeaders() do?
TestContextClientIPWithMultipleHeaders() is a function in the gin codebase, defined in context_test.go.
Where is TestContextClientIPWithMultipleHeaders() defined?
TestContextClientIPWithMultipleHeaders() is defined in context_test.go at line 1163.

Analyze Your Own Codebase

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

Try Supermodel Free