JSONP returns a new Value instance with JSONP decoded from response body. JSONP succeeds if response contains "application/javascript" Content-Type header with empty or "utf-8" charset and response body of the following form: callback( ); or: callback( ) Whitespaces are
(callback string, options ...ContentOpts)
| 944 | // MediaType: "application/javascript", |
| 945 | // }).Array().ConsistsOf("foo", "bar") |
| 946 | func (r *Response) JSONP(callback string, options ...ContentOpts) *Value { |
| 947 | opChain := r.chain.enter("JSONP()") |
| 948 | defer opChain.leave() |
| 949 | |
| 950 | if opChain.failed() { |
| 951 | return newValue(opChain, nil) |
| 952 | } |
| 953 | |
| 954 | if len(options) > 1 { |
| 955 | opChain.fail(AssertionFailure{ |
| 956 | Type: AssertUsage, |
| 957 | Errors: []error{ |
| 958 | errors.New("unexpected multiple options arguments"), |
| 959 | }, |
| 960 | }) |
| 961 | return newValue(opChain, nil) |
| 962 | } |
| 963 | |
| 964 | value := r.getJSONP(opChain, "JSONP()", callback, options...) |
| 965 | |
| 966 | return newValue(opChain, value) |
| 967 | } |
| 968 | |
| 969 | var ( |
| 970 | jsonp = regexp.MustCompile(`^\s*([^\s(]+)\s*\((.*)\)\s*;*\s*$`) |