Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = exports = function dbScope (cfg) {
// when doing head requests, we return the response headers, not the response body
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.

try {
retval = await response.json()
} catch {
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"dependencies": {
},
"devDependencies": {
"undici": "^7.20.0",
"@types/node": "^25.2.1",
"typescript": "^5.9.3"
"undici": "^7.24.6",
"@types/node": "^25.5.0",
"typescript": "^6.0.2"
},
"scripts": {
"test": "tsc lib/nano.d.ts && node --test ./test/*.test.js"
Expand Down
22 changes: 22 additions & 0 deletions test/nano.request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,25 @@ test('check request sends headers for gzipped responses - nano.request', async (
assert.deepEqual(p, response)
mockAgent.assertNoPendingInterceptors()
})


test('check request parses JSON with character set', async () => {
// mocks
const response = { ok: true }
const CHARSET_HEADERS = { headers: { 'content-type': 'application/json; charset=utf-8' } }
mockPool
.intercept({
path: '/db/mydoc'
})
.reply(200, response, CHARSET_HEADERS)

// test GET /db?a=1&b=2
const req = {
method: 'get',
db: 'db',
doc: 'mydoc'
}
const p = await nano.request(req)
assert.deepEqual(p, response)
mockAgent.assertNoPendingInterceptors()
})
Loading