Skip to content

Commit

Permalink
fix: set window option properly (nodejs#2048)
Browse files Browse the repository at this point in the history
* fix: set window option properly

* Update lib/fetch/request.js

Co-authored-by: Robert Nagy <ronagy@icloud.com>

* Update lib/fetch/request.js

Co-authored-by: Robert Nagy <ronagy@icloud.com>

* add test

---------

Co-authored-by: Robert Nagy <ronagy@icloud.com>
  • Loading branch information
2 people authored and crysmags committed Feb 27, 2024
1 parent d4e4ae0 commit a1d3678
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Request {
}

// 11. If init["window"] exists, then set window to "no-window".
if (init.window !== undefined) {
if ('window' in init) {
window = 'no-window'
}

Expand Down
20 changes: 20 additions & 0 deletions test/fetch/407-statuscode-window-null.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const { fetch } = require('../..')
const { createServer } = require('http')
const { once } = require('events')
const { test } = require('tap')

test('Receiving a 407 status code w/ a window option present should reject', async (t) => {
const server = createServer((req, res) => {
res.statusCode = 407
res.end()
}).listen(0)

t.teardown(server.close.bind(server))
await once(server, 'listening')

// if init.window exists, the spec tells us to set request.window to 'no-window',
// which later causes the request to be rejected if the status code is 407
await t.rejects(fetch(`http://localhost:${server.address().port}`, { window: null }))
})

0 comments on commit a1d3678

Please sign in to comment.