Skip to content

Commit 5a580ed

Browse files
authored
fix: get set-cookie w/ credentials: include (nodejs#1454)
1 parent 3b5353a commit 5a580ed

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/fetch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ async function mainFetch (fetchParams, recursive = false) {
654654
// Set response to the following filtered response with response as its
655655
// internal response, depending on request’s response tainting:
656656
if (request.responseTainting === 'basic') {
657-
response = filterResponse(response, 'basic')
657+
response = filterResponse(response, 'basic', request.credentials)
658658
} else if (request.responseTainting === 'cors') {
659659
response = filterResponse(response, 'cors')
660660
} else if (request.responseTainting === 'opaque') {

lib/fetch/response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function makeFilteredHeadersList (headersList, filter) {
407407
}
408408

409409
// https://fetch.spec.whatwg.org/#concept-filtered-response
410-
function filterResponse (response, type) {
410+
function filterResponse (response, type, credentials) {
411411
// Set response to the following filtered response with response as its
412412
// internal response, depending on request’s response tainting:
413413
if (type === 'basic') {
@@ -419,7 +419,7 @@ function filterResponse (response, type) {
419419
type: 'basic',
420420
headersList: makeFilteredHeadersList(
421421
response.headersList,
422-
(name) => !forbiddenResponseHeaderNames.includes(name.toLowerCase())
422+
(name) => credentials === 'include' || !forbiddenResponseHeaderNames.includes(name.toLowerCase())
423423
)
424424
})
425425
} else if (type === 'cors') {

test/fetch/client-fetch.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,21 @@ test('custom agent node fetch', (t) => {
403403
t.strictSame(obj, await body.json())
404404
})
405405
})
406+
407+
test('get set-cookie with credentials: include (#1262)', (t) => {
408+
t.plan(1)
409+
410+
const server = createServer((req, res) => {
411+
res.setHeader('set-cookie', 'hello=world')
412+
res.end('Hello World!')
413+
})
414+
t.teardown(server.close.bind(server))
415+
416+
server.listen(0, async () => {
417+
const { headers } = await fetch(`http://localhost:${server.address().port}`, {
418+
credentials: 'include'
419+
})
420+
421+
t.equal(headers.get('set-cookie'), 'hello=world')
422+
})
423+
})

0 commit comments

Comments
 (0)