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

combine multiple headers using comma #1489

Merged
merged 3 commits into from
Oct 27, 2020
Merged

combine multiple headers using comma #1489

merged 3 commits into from
Oct 27, 2020

Conversation

Lidbetter
Copy link
Contributor

@Lidbetter Lidbetter commented Oct 20, 2020

This addresses issue #1190 (Multiple Set-Cookie headers get aggregated)

https://tools.ietf.org/html/rfc2616#section-4.2

It MUST be possible to combine the multiple header fields into one
"field-name: field-value" pair, without changing the semantics of the
message, by appending each subsequent field-value to the first, each
separated by a comma.

I searched newer RFCs and as far as I can tell the above still holds true

One thing to note, is this:
https://tools.ietf.org/html/rfc6265#section-3

Origin servers SHOULD NOT fold multiple Set-Cookie header fields into
a single header field. The usual mechanism for folding HTTP headers
fields (i.e., as defined in [RFC2616]) might change the semantics of
the Set-Cookie header field because the %x2C (",") character is used
by Set-Cookie in a way that conflicts with such folding.

With that in mind (and some individual header spesific things outlined in other RFCs) it may be better to rework how these headers flow through the application so that multiple headers do not need to be serialized.

For now joining with a comma fixes the set-cookie issue and seems to be more correct than joining with a space

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR. I've put a couple of comments but we're definitely on the way to fix this!

@@ -19,7 +19,7 @@ export const parseResponseBody = (
);

export const parseResponseHeaders = (headers: Dictionary<string[]>): Dictionary<string> =>
mapValues(headers, hValue => hValue.join(' '));
mapValues(headers, hValue => hValue.join(','));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the good change — but I'd say we only need to apply this on the Set-Cookie header instead of doing it for all of them. mapValues is likely offering an overload to also get the key and react accordingly

Copy link
Contributor Author

@Lidbetter Lidbetter Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I didn't initially only special case set-cookie was because of the wording in rfc2616, as far as I can tell joining with a comma is right thing to do by default - a space would be the exception to the general rule.

I could be wrong, do you have a link to more/newer info about the correct way to combine multiple header fields into one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to take a deeper look into; the reason is that it seems like such rule applies only for "state" headers that is Cookies, Caching and some other that now I do not remember.

You can leave it as it is. I'll check it out later or tomorrow and then get back to you.

@@ -78,7 +78,7 @@ describe('parseResponseHeaders()', () => {
expect(parseResponseHeaders({ h1: ['a b'], h2: ['c'], h3: ['a', 'b'] })).toEqual({
h1: 'a b',
h2: 'c',
h3: 'a b',
h3: 'a,b',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also have to write a more specific test to make sure it only happens only under specific conditions.

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've reviewed the entire thing now. While it won't fix a probable issue with Set-Cookie with commas, it should still do the job for now. Thanks

@XVincentX XVincentX merged commit 5d0383a into stoplightio:master Oct 27, 2020
@XVincentX XVincentX added the team/platinum-falcons Team Platinum Falcons label Oct 27, 2020
@Lidbetter Lidbetter deleted the header-serialization branch October 29, 2020 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team/platinum-falcons Team Platinum Falcons
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants