MCPcopy Create free account
hub / github.com/gavv/httpexpect / HasContentType

Method HasContentType

response.go:669–690  ·  view source on GitHub ↗

HasContentType succeeds if response contains Content-Type header with given media type and charset. If charset is omitted, and mediaType is non-empty, Content-Type header should contain empty or utf-8 charset. If charset is omitted, and mediaType is also empty, Content-Type header should contain n

(mediaType string, charset ...string)

Source from the content-addressed store, hash-verified

667// If charset is omitted, and mediaType is also empty, Content-Type header
668// should contain no charset.
669func (r *Response) HasContentType(mediaType string, charset ...string) *Response {
670 opChain := r.chain.enter("HasContentType()")
671 defer opChain.leave()
672
673 if opChain.failed() {
674 return r
675 }
676
677 if len(charset) > 1 {
678 opChain.fail(AssertionFailure{
679 Type: AssertUsage,
680 Errors: []error{
681 errors.New("unexpected multiple charset arguments"),
682 },
683 })
684 return r
685 }
686
687 r.checkContentType(opChain, mediaType, charset...)
688
689 return r
690}
691
692// HasContentEncoding succeeds if response has exactly given Content-Encoding list.
693// Common values are empty, "gzip", "compress", "deflate", "identity" and "br".

Callers 11

TestResponse_UsageFunction · 0.95
ContentTypeMethod · 0.95
TestResponse_FailedChainFunction · 0.80
TestResponse_NoContentFunction · 0.80
TestResponse_ContentTypeFunction · 0.80
TestResponse_TextFunction · 0.80
TestResponse_FormFunction · 0.80
TestResponse_JSONFunction · 0.80
TestResponse_JSONPFunction · 0.80
testChunkedHandlerFunction · 0.80

Calls 5

checkContentTypeMethod · 0.95
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 10

TestResponse_UsageFunction · 0.76
TestResponse_FailedChainFunction · 0.64
TestResponse_NoContentFunction · 0.64
TestResponse_ContentTypeFunction · 0.64
TestResponse_TextFunction · 0.64
TestResponse_FormFunction · 0.64
TestResponse_JSONFunction · 0.64
TestResponse_JSONPFunction · 0.64
testChunkedHandlerFunction · 0.64