Standard library / net/http/httptest
httptest.ResponseRecorder.Header()
Returns the mutable response header map. Inspect Result().Header for committed headers after the handler finishes. Expected stdout: 'before\n'.
Formal Syntax & Structure
go syntaxgo
func (rw *ResponseRecorder) Header() http.HeaderReturn Value
http.Header
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http/httptest")
func main() { w := httptest.NewRecorder() w.Header().Set("X-Demo", "before") w.WriteHeader(200) w.Header().Set("X-Demo", "after") fmt.Println(w.Result().Header.Get("X-Demo"))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}