-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure correct Faraday JSON parsing/response body for invalid respons…
…e header (#110) See my investigation here: #100 (comment) In the Faraday 1 to Faraday 2 process, the ensure JSON response middleware was rewritten from scratch, which caused a change in how permissive the middleware was to response Content-Type headers which did not properly indicate a JSON response. In Faraday 1.x, the JSON middleware would attempt a JSON parse of the body, regardless of the presence or value of a Content-Type header. This meant that Graphlient would have raised an exception (or re-raised one caught from Faraday) if the response body was not valid JSON. In Faraday 2.x, the new JSON middleware will only attempt to parse the response body if it determines that the Content-Type response header indicates a JSON body. By default it uses a regex on the header value (/\bjson$/ at the time of writing). Crucially, if the header is missing, or does not match the regex, instead of raising an exception, `Faraday::Response#body` returns a String, rather than the previously-assumed Hash or Array. This change restores the parsing logic which is tolerant to incorrect or missing Content-Type header values. Response bodies which are not valid JSON will raise an exception. Any unforseen situation where `#body` returns a type that is not String, Hash, or Array, will raise a separate exception detailing that this is unexpected behavior and a bug should be filed. Resolves #100
- Loading branch information
1 parent
3638cd8
commit 423afee
Showing
3 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters