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)
| 667 | // If charset is omitted, and mediaType is also empty, Content-Type header |
| 668 | // should contain no charset. |
| 669 | func (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". |