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

Headers ordering #162

Closed
eLRuLL opened this issue Aug 31, 2015 · 5 comments
Closed

Headers ordering #162

eLRuLL opened this issue Aug 31, 2015 · 5 comments

Comments

@eLRuLL
Copy link

eLRuLL commented Aug 31, 2015

In some cases headers order matter, like here

Could this be changed somehow? and why is it important to handle headers on a gb_tree structure?

@etrepum
Copy link
Member

etrepum commented Aug 31, 2015

The gb_tree data structure is necessary for performance reasons. What's your use case? When multiple headers with the same name are present, they are combined in the order that they were received.

`> mochiweb_headers:to_list(mochiweb_headers:make([{"foo", "a"}, {"foo", "b"}])).
[{"foo","a, b"}]

@eLRuLL
Copy link
Author

eLRuLL commented Aug 31, 2015

I am using mochiweb like a proxy, so I need to pass a server response to the client and the server response headers are like:

Set-Cookie: selectedCountry=US; Expires=Sat, 29 Aug 2015 15:16:49 GMT; Path=/; Domain=.example.com
Set-Cookie: selectedCountry=GB; Expires=Sat, 29 Aug 2015 15:16:49 GMT; Path=/; Domain=.example.com

but when passing through mochiweb, it returns:

Set-Cookie: selectedCountry=GB; Expires=Sat, 29 Aug 2015 15:16:49 GMT; Path=/; Domain=.example.com
Set-Cookie: selectedCountry=US; Expires=Sat, 29 Aug 2015 15:16:49 GMT; Path=/; Domain=.example.com

Which sets incorrect cookie on the client side.

@etrepum
Copy link
Member

etrepum commented Aug 31, 2015

Order for Set-Cookie is preserved. Are you doing some sort of transformation? How exactly are you generating the headers for the response?

1> mochiweb_headers:to_list(mochiweb_headers:make([{"Set-Cookie", "selectedCountry=GB"}, {"Set-Cookie", "selectedCountry=US"}])).
[{"Set-Cookie","selectedCountry=GB"},
 {"Set-Cookie","selectedCountry=US"}]

This ordering property is tested (in a few places, here's one):

set_cookie_test() ->
    H = make([{"set-cookie", foo}, {"set-cookie", bar}, {"set-cookie", baz}]),
    ?assertEqual(
       [{"set-cookie", "foo"}, {"set-cookie", "bar"}, {"set-cookie", "baz"}],
       to_list(H)),
    ok.

@etrepum
Copy link
Member

etrepum commented Aug 31, 2015

Ok, I found the issue, it's with formatting the headers in the response, not with mochiweb_headers itself.

@eLRuLL
Copy link
Author

eLRuLL commented Sep 1, 2015

thanks for this 👍

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

No branches or pull requests

2 participants