Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rawHeaders to HttpResponse #165

Merged
merged 3 commits into from
Dec 28, 2021
Merged

Add rawHeaders to HttpResponse #165

merged 3 commits into from
Dec 28, 2021

Conversation

fredrikhr
Copy link
Contributor

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) and Set-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 the HttpResponse 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).

@AnWeber
Copy link
Owner

AnWeber commented Dec 27, 2021

Thank you for the detailed explanation. Fortunately, I would not have to know this detail yet.
You might want to add the rawHeaders to the copy function as well. I will have a look at that tomorrow, if it is really needed

@AnWeber AnWeber merged commit 6712e55 into AnWeber:main Dec 28, 2021
AnWeber pushed a commit that referenced this pull request Dec 28, 2021
@AnWeber
Copy link
Owner

AnWeber commented Dec 28, 2021

Thank you. I have removed the rawHeaders on output of JSON (httpyac --json). I think here they are not needed. There is a similar place in vscode-httpyac. I'll remove that one too. But otherwise it should fit.

AnWeber added a commit to AnWeber/vscode-httpyac that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants