unjs / unjs/node-mock-http

writeHead ignores headers passed as an array

Open Beginner friendly
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
17
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Environment
  • Node v26.7.0
  • node-mock-http@1.0.5
Reproduction

See description.

Describe the bug

ServerResponse.writeHead() accepts headers as an object or as an array.

The problem is that the array condition https://github.com/unjs/node-mock-http/blob/84897e45fcc67169858b86272235257f2e73f521/src/http/response.ts#L67 is unfinished... so those headers are just missing.

import { ServerResponse, IncomingMessage } from "node-mock-http";

const res = new ServerResponse(new IncomingMessage());
res.writeHead(200, ["content-type", "image/jpeg"]);

res.getHeaders();  // {}   <- expected { "content-type": "image/jpeg" }
Additional context

No response

Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/http/response.ts around line 67, where ServerResponse.writeHead handles the array form of headers. Run the provided Node reproduction and verify that getHeaders() returns the content-type entry for an array argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.