Skip to content

Ensure that all application/json responses are parsed as JSON#368

Merged
glynnbird merged 1 commit intomainfrom
grb-handle-charset-in-content-type
Apr 1, 2026
Merged

Ensure that all application/json responses are parsed as JSON#368
glynnbird merged 1 commit intomainfrom
grb-handle-charset-in-content-type

Conversation

@glynnbird
Copy link
Copy Markdown
Contributor

Overview

Issue #366 reported that a content-type of application/json; charset=utf-8 was not being parsed as json. This PR fixes that.

Testing recommendations

Automated test added to try a content-type with a charset.

GitHub issue number

Fixes issue #366.

Related Pull Requests

n/a

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

…racter set are parsed as JSON. Fixes issue #366
@glynnbird glynnbird requested a review from janl April 1, 2026 08:07
Comment thread lib/nano.js
if (req.method === 'head') {
retval = Object.fromEntries(response.headers)
} else if (contentType === 'application/json') {
} else if (contentType && contentType.startsWith('application/json')) {
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.

Short question: Are these headers always trimmed before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've just checked, and they are not! 🫤

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not going to worry about it just now.

@glynnbird glynnbird merged commit 87b644a into main Apr 1, 2026
3 checks passed
@glynnbird glynnbird deleted the grb-handle-charset-in-content-type branch April 1, 2026 09:05
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.

3 participants