sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Body required on DELETE request #1966

Closed DanCurryy closed 2 years ago

DanCurryy commented 2 years ago

Describe the bug

When attempting DELETE request without a body option, got hangs before timing out.

Provided a minimal recreation below where it fails to enter any event handler when options.body is not set to some value.

Actual behavior

Does not enter any event handler.

Expected behavior

Expect to see the logging for res and end at the very least, but neither are ever called.

Code to reproduce

const options = {
  url: 'https://httpbin.org/delete',
  method: 'DELETE'
}

const makeRequest = async (options) => {
  const { default: got } = await import('got')
  const ourRequestStream = got.stream(options)
  ourRequestStream
    .on('response', (response) => {
      console.log('res')
    })
    .on('data', (response) => {
      console.log('data')
    })
    .on('end', (response) => {
      console.log('end')
    })
    .on('error', (e) => {
      console.log('error')
    })
}

makeRequest(options)

Checklist

szmarczak commented 2 years ago

Body is not required on DELETE. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE

Can you provide a repro with native Node.js server?