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

Stream Body is not sent when using DELETE #1758

Open
XiaoXice opened this issue Jun 20, 2023 · 0 comments
Open

Stream Body is not sent when using DELETE #1758

XiaoXice opened this issue Jun 20, 2023 · 0 comments
Labels

Comments

@XiaoXice
Copy link

Reproduction

When using Stream and DELETE at the same time, the Body is not sent.

Here is my reproduction code and comparison code.

import { Readable } from "stream";
import fetch from "node-fetch";

function jsonReadable() {
  const stream = new Readable({
    read() {},
  });

  setTimeout(() => {
    stream.push('{"id":6,"delete_mark":0}');
    stream.push(null);
  }, 1000);
  return stream;
}
{
  const resBox = await fetch("https://httpbin.org/post", {
    method: "POST",
    body: jsonReadable(),
  });
  const data = await resBox.json();
  console.log(data);
} 
/**
{
  args: {},
  data: '{"id":6,"delete_mark":0}',
  files: {},
  form: {},
  headers: {
    "Accept-Encoding": "gzip, deflate, br",
    Host: "httpbin.org",
    "Transfer-Encoding": "chunked",
    "User-Agent": "node-fetch",
    "X-Amzn-Trace-Id": "Root=1-6491434c-7e6794f35fef470f4947803b",
  },
  json: { delete_mark: 0, id: 6 },
  url: "https://httpbin.org/post",
}
*/
{
  const resBox = await fetch("https://httpbin.org/delete", {
    method: "DELETE",
    body: jsonReadable(),
  });
  const data = await resBox.json();
  console.log(data);
/**
{
  args: {},
  data: "",
  files: {},
  form: {},
  headers: {
    "Accept-Encoding": "gzip, deflate, br",
    Host: "httpbin.org",
    "User-Agent": "node-fetch",
    "X-Amzn-Trace-Id": "Root=1-64914334-1b83650b7523b5c96a12b485",
  },
  json: null,
  url: "https://httpbin.org/delete",
}
*/
}
{
  const resBox = await fetch("https://httpbin.org/delete", {
    method: "DELETE",
    body: JSON.stringify({ id: 6, delete_mark: 0 }),
  });
  const data = await resBox.json();
  console.log(data);
/**
{
  args: {},
  data: '{"id":6,"delete_mark":0}',
  files: {},
  form: {},
  headers: {
    "Accept-Encoding": "gzip, deflate, br",
    "Content-Length": "24",
    "Content-Type": "text/plain;charset=UTF-8",
    Host: "httpbin.org",
    "User-Agent": "node-fetch",
    "X-Amzn-Trace-Id": "Root=1-649146b6-0c217a394a1dcb4b6f10d8be",
  },
  json: { delete_mark: 0, id: 6 },
  url: "https://httpbin.org/delete",
}
*/
}

Expected behavior

I hope that the Stream can be sent normally when using the DELETE method.

Your Environment

software version
node-fetch 3.3.1 & 3.2.6
node v16.15.1
npm 8.11.0
Operating System MacOS 12.0.1
@XiaoXice XiaoXice added the bug label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant