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

Support for concatenation of headers #4864

Merged
merged 5 commits into from
Oct 4, 2018
Merged

Support for concatenation of headers #4864

merged 5 commits into from
Oct 4, 2018

Conversation

sophienyaa
Copy link
Contributor

If the server returns several headers of the same key (e.g Set-Cookie) only the last one is returned, causing issues in communicating with some servers where cookies are required.

This change concatenates the headers of the same key separated by ";" to alleviate this issue

If the server returns several headers of the same key (e.g Set-Cookie) only the last one is returned, causing issues in communicating with some servers where cookies are required.

This change concatenates the headers of the same key separated by ";" to alleviate this issue
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

Seems fine with the one comment. Do you have a public site that has this behavior to test against?

@@ -1026,7 +1026,7 @@ int HTTPClient::handleHeaderResponse()

for(size_t i = 0; i < _headerKeysCount; i++) {
if(_currentHeaders[i].key.equalsIgnoreCase(headerName)) {
_currentHeaders[i].value = headerValue;
_currentHeaders[i].value += headerValue + ";";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we follow the HTTP spec and use a , instead for concatenation?

RFC 2616

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree on the , A comma is definitely the expected concatenation character.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also looks like this is going to mess up the default, single-header case by adding an illegal/unneeded ";" (or "," once fixed to match RFC 2616) to all values.

@earlephilhower earlephilhower self-assigned this Oct 3, 2018
Change ";" to "," to match the HTTP specs.

Add ",<nextval>" on each additional value instead of adding a
comma automatically after every value, even single ones.
@earlephilhower
Copy link
Collaborator

Verified multiple Set-Cookie lines concatenate properly and single-line headers don't get any add'l unneeded commas.

@earlephilhower
Copy link
Collaborator

I'll let this go as-is, but it doesn't actually help for cookies proper. Set-Cookie headers seem to include both , and ; and so you can't use a concat'ed string to set individual cookies because splitting it is non-deterministic.

To do it right and support multiple cookies, we will need to have this call return an iterator and potentially a whole series of individual strings for parsing. It's doable, but not something I can fix in the online editor.

For example, see the following header set from GOOG:

[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 200 OK'
[HTTP-Client][handleHeaderResponse] RX: 'Date: Thu, 04 Oct 2018 03:35:13 GMT'
[HTTP-Client][handleHeaderResponse] RX: 'Expires: -1'
[HTTP-Client][handleHeaderResponse] RX: 'Cache-Control: private, max-age=0'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/html; charset=ISO-8859-1'
[HTTP-Client][handleHeaderResponse] RX: 'P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."'
[HTTP-Client][handleHeaderResponse] RX: 'Server: gws'
[HTTP-Client][handleHeaderResponse] RX: 'X-XSS-Protection: 1; mode=block'
[HTTP-Client][handleHeaderResponse] RX: 'X-Frame-Options: SAMEORIGIN'
[HTTP-Client][handleHeaderResponse] RX: 'Set-Cookie: 1P_JAR=2018-10-04-03; expires=Sat, 03-Nov-2018 03:35:13 GMT; path=/; domain=.google.com'
:c 1, 536, 1072
[HTTP-Client][handleHeaderResponse] RX: 'Set-Cookie: NID=140=g70gxMT35ZROzCbLx8AO7KTjmIbw4GoOCddaseHafS7QceQFbO7covx5i9xydvSun0nKEJP4b7vKqvD0On8X6H3kZ1JCOWXMQnTAE_Kcw6oiqXiDOYOiE8E_HsMCFVZ8PsiK; expires=Fri, 05-Apr-2019 03:35:13 GMT; path=/; domain=.google.com; HttpOnly'
[HTTP-Client][handleHeaderResponse] RX: 'Accept-Ranges: none'
[HTTP-Client][handleHeaderResponse] RX: 'Vary: Accept-Encoding'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''

@earlephilhower earlephilhower merged commit 1de0c34 into esp8266:master Oct 4, 2018
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.

3 participants