Home / Function/ TestInterceptedHeader() — gin Function Reference

TestInterceptedHeader() — gin Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

context_test.go lines 3341–3368

func TestInterceptedHeader(t *testing.T) {
	w := httptest.NewRecorder()
	c, r := CreateTestContext(w)

	r.Use(func(c *Context) {
		i := interceptedWriter{
			ResponseWriter: c.Writer,
			b:              bytes.NewBuffer(nil),
		}
		c.Writer = i
		c.Next()
		c.Header("X-Test", "overridden")
		c.Writer = i.ResponseWriter
	})
	r.GET("/", func(c *Context) {
		c.Header("X-Test", "original")
		c.Header("X-Test-2", "present")
		c.String(http.StatusOK, "hello world")
	})
	c.Request = httptest.NewRequest(http.MethodGet, "/", nil)
	r.HandleContext(c)
	// Result() has headers frozen when WriteHeaderNow() has been called
	// Compared to this time, this is when the response headers will be flushed
	// As response is flushed on c.String, the Header cannot be set by the first
	// middleware. Assert this
	assert.Empty(t, w.Result().Header.Get("X-Test"))
	assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free