Skip to content

HTTP2ServerRequest headers cannot be set but they can be mutated using Object.assign #61851

@TusharShahi

Description

@TusharShahi

Version

v20.11.1

Platform

In the docs linked here - https://nodejs.org/api/all.html#all_http2_headers-object:~:text=In%20HTTP/2%2C%20the%20request%20path%2C, we see this statement:

 Care must be taken not to inadvertently modify these special headers or errors may occur. For instance, removing all headers from the request will cause errors to occur:



And also in the source code setter is missing for headers

https://github.com/nodejs/node/blob/1523d66a695ad1d1743e84966ff11859cc3dfd54/lib/internal/http2/compat.js#L310


But we are able to update the headers using Object.assign.

Should that be allowed?

Subsystem

No response

What steps will reproduce the bug?

  1. Use context.req.headers = newRandomObject. This will throw an error.
  2. Use Object.assign(context.req.headers, someObject). This will not throw an error.

How often does it reproduce? Is there a required condition?

Everytime

What is the expected behavior? Why is that the expected behavior?

For it to consistently throw an error in both cases

What do you see instead?

No error

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions