Text returns a new String instance with response body. Text succeeds if response contains "text/plain" Content-Type header with empty or "utf-8" charset. Example: resp := NewResponse(t, response) resp.Text().IsEqual("hello, world!") resp.Text(ContentOpts{ MediaType: "text/plain", }).IsEqua
(options ...ContentOpts)
| 759 | // MediaType: "text/plain", |
| 760 | // }).IsEqual("hello, world!") |
| 761 | func (r *Response) Text(options ...ContentOpts) *String { |
| 762 | opChain := r.chain.enter("Text()") |
| 763 | defer opChain.leave() |
| 764 | |
| 765 | if opChain.failed() { |
| 766 | return newString(opChain, "") |
| 767 | } |
| 768 | |
| 769 | if len(options) > 1 { |
| 770 | opChain.fail(AssertionFailure{ |
| 771 | Type: AssertUsage, |
| 772 | Errors: []error{ |
| 773 | errors.New("unexpected multiple options arguments"), |
| 774 | }, |
| 775 | }) |
| 776 | return newString(opChain, "") |
| 777 | } |
| 778 | |
| 779 | if !r.checkContentOptions(opChain, options, "text/plain") { |
| 780 | return newString(opChain, "") |
| 781 | } |
| 782 | |
| 783 | content, ok := r.getContent(opChain, "Text()") |
| 784 | if !ok { |
| 785 | return newString(opChain, "") |
| 786 | } |
| 787 | |
| 788 | return newString(opChain, string(content)) |
| 789 | } |
| 790 | |
| 791 | // Form returns a new Object instance with form decoded from response body. |
| 792 | // |