apitest
Assertions

Headers

Assert on header values, and on whether a header is present.

apitest.Handler(handler).
	Get("/user/1234").
	Expect(t).
	Status(http.StatusOK).
	Header("Content-Type", "application/json").
	Headers(map[string]string{"X-Request-Id": "12345"}).
	HeaderPresent("Etag").
	HeaderNotPresent("X-Powered-By").
	End()
MethodPasses when
Header(key, value)The header exists and one of its values equals value.
Headers(map[string]string)Each entry passes as it would with Header.
HeaderPresent(key)The header exists, whatever its value, including an empty value.
HeaderNotPresent(key)The header does not exist.

Values are compared exactly. A header with several values, such as Vary: Accept and Vary: Origin, passes Header("Vary", "Origin") because one of its values matches.

Header names are canonicalised, so content-type and Content-Type are the same header.

To match a header value with a pattern, or to compare a value such as a date loosely, use a custom assertion.