Skip to content

Improve ERR_INVALID_CHAR error info #28797

@gengjiawen

Description

@gengjiawen

Is your feature request related to a problem? Please describe.
Recently, I have debug a error with http header

(node:17863) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["cookie"]
    at ClientRequest.setHeader (_http_outgoing.js:458:3)
    at new ClientRequest (_http_client.js:221:14)
    at Object.request (http.js:44:10)

I take a very long time to find the invalid character (the root cause is because I put \n in the string end, so it failed).

Describe the solution you'd like
The error provide more information

Describe alternatives you've considered
Hopefully we can change something here to return more info

node/lib/_http_common.js

Lines 227 to 230 in ba565a3

function checkInvalidHeaderChar(val) {
return headerCharRegex.test(val);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    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