Skip to content

HTTP module, multiple headers with same name #14200

@ghost

Description

  • Version: All versions from what I can tell
  • Platform: All
  • Subsystem: http module

The problem is pretty straight forward. There is no good way to send out multiple headers with the same name. I literally had to resort to this jank solution:

http.ServerResponse.prototype.sendRawHeader = function(name, value){
	if(!this._headerSent){
		this.connection.write(['HTTP/1.1', this.statusCode, STATUS_CODES[this.statusCode], '\r\n'].join(' '));

	}
	this.connection.write([ [name, ':'].join(''), [value, '\r\n'].join('') ].join(' '));
}

This is still bad in my personal opinion as I'm having to write headers out before content and the module should be handling the status code for me.

While everyone seems to cite that headers should be capable of being handled as comma separated values, this does not work cross-platform in ever situation. The easiest thing to cite would be sending out multiple Set-Cookie headers like so:

Set-Cookie: uid=n
Set-Cookie: token=XXX-XXXX-XXX-XXXX

There is absolutely no way to do this and this will never work cross-browser or cross-platform

Set-Cookie: uid=n, token=XXX-XXXX-XXX-XXXX

There are other situations with custom software that I've dealt with where other headers need to be sent in multiple lines in order for proper evaluation.

I propose that a function be added like http.ServerResponse.addRawHeader(string) and in the response portion of the HTTP module, a variable (array) named additionalRawHeaders be used to track these headers. When headers are finally sent, the last part would be to iterate through additionalRawHeaders and just write those out to the socket.

If no one agrees with this, if I just write it myself, what are the chances a pull request will be accepted for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.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