Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): do not assign default value to RequestInit.method #1529

Merged
merged 1 commit into from Jul 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Expand Up @@ -95,7 +95,7 @@ class Fetch extends EE {
}

// https://fetch.spec.whatwg.org/#fetch-method
async function fetch (input, init = undefined) {
async function fetch (input, init = {}) {
if (arguments.length < 1) {
throw new TypeError(
`Failed to execute 'fetch' on 'Window': 1 argument required, but only ${arguments.length} present.`
Expand Down
3 changes: 1 addition & 2 deletions lib/fetch/request.js
Expand Up @@ -843,8 +843,7 @@ webidl.converters.AbortSignal = webidl.interfaceConverter(
webidl.converters.RequestInit = webidl.dictionaryConverter([
{
key: 'method',
converter: webidl.converters.ByteString,
defaultValue: 'GET'
converter: webidl.converters.ByteString
},
{
key: 'headers',
Expand Down
21 changes: 21 additions & 0 deletions test/fetch/client-fetch.js
Expand Up @@ -9,6 +9,7 @@ const { Blob } = require('buffer')
const { fetch, Response, Request, FormData, File } = require('../..')
const { Client, setGlobalDispatcher, Agent } = require('../..')
const nodeFetch = require('../../index-fetch')
const { once } = require('events')

setGlobalDispatcher(new Agent({
keepAliveTimeout: 1,
Expand Down Expand Up @@ -419,3 +420,23 @@ test('error on redirect', async (t) => {
t.equal(errorCause.message, 'unexpected redirect')
})
})

// https://github.com/nodejs/undici/issues/1527
test('fetching with Request object - issue #1527', async (t) => {
const server = createServer((req, res) => {
t.pass()
res.end()
}).listen(0)

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

const body = JSON.stringify({ foo: 'bar' })
const request = new Request(`http://localhost:${server.address().port}`, {
method: 'POST',
body
})

await t.resolves(fetch(request))
t.end()
})