From 9539cfa35817ea3ad61eccd2ed0572cc5c449d03 Mon Sep 17 00:00:00 2001 From: Shogun Date: Mon, 10 Jan 2022 21:50:58 +0100 Subject: [PATCH] http: add uniqueHeaders option to request and createServer PR-URL: https://github.com/nodejs/node/pull/41397 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina --- doc/api/http.md | 72 +++++++- lib/_http_client.js | 8 +- lib/_http_incoming.js | 50 ++++++ lib/_http_outgoing.js | 82 +++++++++- lib/_http_server.js | 8 +- test/parallel/test-http-multiple-headers.js | 173 ++++++++++++++++++++ 6 files changed, 380 insertions(+), 13 deletions(-) create mode 100644 test/parallel/test-http-multiple-headers.js diff --git a/doc/api/http.md b/doc/api/http.md index 01c97ec4e671db..838cdd0e05f9be 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2364,8 +2364,28 @@ header name: `last-modified`, `location`, `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, or `user-agent` are discarded. * `set-cookie` is always an array. Duplicates are added to the array. -* For duplicate `cookie` headers, the values are joined together with '; '. -* For all other headers, the values are joined together with ', '. +* For duplicate `cookie` headers, the values are joined together with `; `. +* For all other headers, the values are joined together with `, `. + +### `message.headersDistinct` + + + +* {Object} + +Similar to [`message.headers`][], but there is no join logic and the values are +always arrays of strings, even for headers received just once. + +```js +// Prints something like: +// +// { 'user-agent': ['curl/7.22.0'], +// host: ['127.0.0.1:8000'], +// accept: ['*/*'] } +console.log(request.headersDistinct); +``` ### `message.httpVersion` @@ -2499,6 +2519,18 @@ added: v0.3.0 The request/response trailers object. Only populated at the `'end'` event. +### `message.trailersDistinct` + + + +* {Object} + +Similar to [`message.trailers`][], but there is no join logic and the values are +always arrays of strings, even for headers received just once. +Only populated at the `'end'` event. + ### `message.url` + +* `name` {string} Header name +* `value` {string|string\[]} Header value +* Returns: {this} + +Append a single header value for the header object. + +If the value is an array, this is equivalent of calling this method multiple +times. + +If there were no previous value for the header, this is equivalent of calling +[`outgoingMessage.setHeader(name, value)`][]. + +Depending of the value of `options.uniqueHeaders` when the client request or the +server were created, this will end up in the header being sent multiple times or +a single time with values joined using `; `. + ### `outgoingMessage.connection`