Skip to content

Normalize response media types before decoding - #52

Merged
strzibny merged 1 commit into
serpapi:masterfrom
ItsM0rty:code-fix/response-media-type
Dec 2, 2026
Merged

strzibny merged 1 commit into
serpapi:masterfrom
ItsM0rty:code-fix/response-media-type

Conversation

@ItsM0rty

@ItsM0rty ItsM0rty commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #51.

search(output: 'md') or search(output: 'html') could try to parse the response as JSON when a valid Content-Type used different casing or whitespace before charset. Normalize the media type before choosing the decoder.

Both cases fail on master in the mocked Ruby probe and pass w/ the fix. The offline RSpec run passed 35 examples w/o calling the live API.

@strzibny strzibny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although not a problem on production, I can see how this makes mocking harder and less intuitive. Thank you @ItsM0rty!

@strzibny
strzibny merged commit a40f49a into serpapi:master Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Valid Content-Type headers can make search parse HTML or Markdown as JSON

2 participants