Skip to content

doesn't correctly handle multiple content-type values #783

@char0n

Description

@char0n

I found a peculiar issue of incompatibility of this library comparing to native browser fetch version. Affected version 2.6.0

Steps to reproduce:

1.) Create simple node server and run it

const http = require('http');

const requestListener = function (req, res) {
  res.setHeader('Cookie', ['one=1', 'two=2']);
  res.setHeader('Content-Type', ['text/plain', 'application/json']);
  res.writeHead(200);
  res.end('Hello, World!');
}

const server = http.createServer(requestListener);
server.listen(8080);

2.) Fetch the server

In browser

fetch('http://localhost:8080').then(r => r.headers).then(h => h.get('Content-Type')).then(console.dir);
// text/plain, application/json

node-fetch

fetch('http://localhost:8080').then(r => r.headers).then(h => h.get('Content-Type')).then(console.dir);
// text/plain

As you can see, node-fetch doesn't correctly handle multiple headers with the same name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions