Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As per the documentation from node.js (which is also used by got), HTTP headers from the response are (in most cases) merged together by joining multiple values from equal-named headers with
', '
. (I.e. multiple x-some-header headers are combined to one header value with<value1>, <value2>, etc.
).In most cases that is fine as there is some special handling for some default headers (e.g.
User-Agent
(multiple values are discarded) andSet-Cookie
(value is always an array).However, I find myself in a situation where I need to handle multiple values for a header. And to makes matters even worse, I need to parse these headers and the syntax I am parsing contains
,
. In such a case the intelligent header handling of got is not helpful.For such purposes I propose that we add a new property
rawHeaders
to theHttpResponse
type which is populated from the same-named property from the got Response object.Because the got raw-headers are a little cumbersome to work with, I propose to also add a merging helper function that combines equal named headers into arrays and group them by lower-cased header names. That way you can easily get the best of both worlds with little effort (i.e. simply pass the raw-headers into the helper function), while not requiring extra work to be done if you don't need it (
rawHeaders
is already accessible in the got HTTP Response object).