Skip to content

getHeader() returns undefined after using writeHead() in a certain circumstance #10354

Closed
@DevAndrewGeorge

Description

@DevAndrewGeorge
  • Version: 6.9.1
  • Platform: Linux 4.4.0-21-generic logo ideas #37-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: http

In short, calling writeHead() with a ServerResponse object which has no headers already set causes getHeader() to return undefined even if the header was set in the writeHead() function call. I am unfamiliar with the project, so I'm unsure if this is defined behavior or not.

//Case 1: using setHeader, getHeader works as intended
res.setHeader("Location", "index.html");
res.getHeader("Location"); //index.html

//Case 2: using setHeader then writeHead, getHeader works as intended
res.setHeader("Set-Cookie", "hello=world");
res.writeHead(303, {Location: "index.html"});
res.getHeader("Location"); //index.html

//Case 3: using writeHead when res._headers is null, getHeader does not work as intended
res.writeHead(303, {Location: "index.html"});
res.getHeader("Location"); //undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions