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

When multiple headers have the same key, only one is preserved #292

Open
mottersheadt opened this issue May 20, 2022 · 8 comments
Open

When multiple headers have the same key, only one is preserved #292

mottersheadt opened this issue May 20, 2022 · 8 comments

Comments

@mottersheadt
Copy link
Contributor

Problem or feature statement

input.headers does not support multi-dict. If there are 2 Set-Cookie headers in an HTTP response, the second one gets deleted.

Advised solution

We should use the multi-dict feature in Larky to support having multiple headers with the same key.

@mahmoudimus
Copy link
Contributor

input.headers should return a list of tuples. If you want to use multidict, then you can just multidict(input.headers).

Does that work for you?

@mottersheadt
Copy link
Contributor Author

I'll test. Currently the headers can be referenced like this: input.headers['header-name']. Are you saying that under the hood it's actually a list of tuples, and the dictionary reference method is just syntactic sugar?

@mahmoudimus
Copy link
Contributor

No, I mean the ask here is that you want headers back as a multidict instead of a list of tuples. I am saying, if you want multidict, then just pass the list of tuples into the multidict instead of expecting headers to come back as a multidict by default :)

@mottersheadt
Copy link
Contributor Author

Ah - I was misunderstanding the structure. I thought the headers were already a dictionary. Calling mutlidict should work. I'll let you know if I hit any blockers.

@mahmoudimus
Copy link
Contributor

@mottersheadt this needs to be re-opened because input.headers needs to return a list of tuples. It does not right now.

@mottersheadt
Copy link
Contributor Author

Ok. Won't it be dangerous to switch it to a list of tuples at this point? Everyone who has currently implemented Larky scripts using the header dictionary will have their routes break. I think moving it to a multi-dictionary would be more backwards compatible.

@mahmoudimus
Copy link
Contributor

It depends which FCO, I think.

@mottersheadt
Copy link
Contributor Author

Here is the current syntax for github.com/verygoodsecurity/common/compute/larky/http/Process. Need to make sure we don't break how it currently works.

                    def process(input, ctx):
                      if 'Authority' in input.headers:
                        input.headers['Authority'] = re.sub('new-test.com', 'test.com', input.headers['Authority'])
                      
                      return input

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