Skip to content

send_response: fix multi-valued response headers#54

Merged
TimWolla merged 3 commits intoTimWolla:mainfrom
wolf-cosmose:fix-multiple-headers
Jul 13, 2022
Merged

send_response: fix multi-valued response headers#54
TimWolla merged 3 commits intoTimWolla:mainfrom
wolf-cosmose:fix-multiple-headers

Conversation

@wolf-cosmose
Copy link
Copy Markdown
Contributor

Joining the values with a comma, like get_headers(true) does, is invalid for some headers, eg. Set-Cookie.

Instead, use get_headers(false) to have separate loop iterations for each value of the header.
This way we have a separate add_header call for each value, and let haproxy take care of the rest.

Joining the values with a comma, like get_headers(true) does,
 is invalid for some headers, eg. Set-Cookie.

Instead, use get_headers(false) to have separate loop iterations
for each value of the header.

This way we have a separate add_header call for each value,
and let haproxy take care of the rest.
@TimWolla
Copy link
Copy Markdown
Owner

TimWolla commented Jul 8, 2022

Thanks for your PR. Can you please add a test: https://github.com/TimWolla/haproxy-auth-request/tree/main/test? Testing is done with VTest. You can find an example in the GitHub Actions config:

vtest -Dhaproxy_version=${{ steps.install-haproxy.outputs.version }} -k -t 10 test/*.vtc 2>&1 \
and in the test README of HAProxy itself: https://github.com/haproxy/haproxy/blob/master/reg-tests/README

@wolf-cosmose
Copy link
Copy Markdown
Contributor Author

Should I add a new test, or extend one of the existing tests?

@TimWolla
Copy link
Copy Markdown
Owner

TimWolla commented Jul 8, 2022

A new test (or even several new tests if that makes sense), please. I've taken care to ensure that all tests only test some very specific part, as that makes it easier to find the actual issue and it keeps the test simple.

@wolf-cosmose
Copy link
Copy Markdown
Contributor Author

Looks like VTest has no way to check multi-valued headers. It just finds the first occurrence and looks at that.
So my test will be only able to check that the values don't get joined with commas, but not that all of them are passed.

@TimWolla
Copy link
Copy Markdown
Owner

TimWolla commented Jul 8, 2022

Looks like VTest has no way to check multi-valued headers. It just finds the first occurrence and looks at that.

Oh, that's not good! Thank you for adding the test, even though it doesn't check everything. It helps me understand the issue and expected solution a little better.

I'll see if I can adjust the test to verify this properly. It should be possible to pass the response through a dedicated frontend/backend and perform the counting / checking with HAProxy ACLs.

I don't expect you to make any further changes here, I've put it on my TODO to handle the rest.

@TimWolla TimWolla added the bug Something isn't working label Jul 8, 2022
@TimWolla TimWolla self-requested a review July 8, 2022 14:41
@TimWolla TimWolla enabled auto-merge (squash) July 13, 2022 20:20
@TimWolla TimWolla merged commit f91c81e into TimWolla:main Jul 13, 2022
@TimWolla
Copy link
Copy Markdown
Owner

Now merged (with an improved test). Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants