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

don't duplicate accept-encoding in vary header #2796

Merged
merged 1 commit into from Oct 2, 2015

Conversation

ldesplat
Copy link
Contributor

This is in relation hapijs/h2o2#17 .

accept-encoding value in vary header was being duplicated. This fixes the issue and adds a test case to cover the scenario.

I could have fixed it instead in lib/response.js, to not add a value if it already exists in a header but I thought that was too brittle to do there.

PS: forgot to say, I will make a lts PR if this is accepted.

@@ -227,7 +227,7 @@ internals.transmit = function (response, callback) {

// Content-Encoding

if (request.headers['accept-encoding']) {
if (request.headers['accept-encoding'] && (!response.headers.vary || response.headers.vary.indexOf('accept-encoding') === -1) ) {
response.vary('accept-encoding');
Copy link
Contributor

Choose a reason for hiding this comment

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

Better done inside he response.vary() method in a generic way.

@ldesplat
Copy link
Contributor Author

You are right and much easier. Updated the PR. Added 1 more test and kept the old one since I thought it was still relevant.


for (var i = 0, il = values.length; i < il; ++i) {
if (values[i] === value) {
foundMatch = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just return here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have but there appears to be opportunities to return early in this function and it was not done. So, I was following the current flow and decided to break. Returning early does save an allocation and I am already doing split so I just changed it. Thanks!

@ldesplat
Copy link
Contributor Author

ldesplat commented Oct 2, 2015

Any update on this? I would love to get it going so I can do a PR for lts and get h2o2 updated! Thank you :)

@hueniverse hueniverse added the bug Bug or defect label Oct 2, 2015
@hueniverse hueniverse added this to the 10.2.0 milestone Oct 2, 2015
@hueniverse hueniverse self-assigned this Oct 2, 2015
hueniverse added a commit that referenced this pull request Oct 2, 2015
don't duplicate accept-encoding in vary header
@hueniverse hueniverse merged commit 6c5ab9f into hapijs:master Oct 2, 2015
hueniverse added a commit that referenced this pull request Oct 2, 2015
@ldesplat
Copy link
Contributor Author

ldesplat commented Oct 2, 2015

@nlf could this be included in LTS branch? h2o2 tests fail when upgrading to hapi 9.x.x otherwize.

@nlf
Copy link
Member

nlf commented Oct 2, 2015

it will be. i'll release a new LTS after 10.2.0 is released

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants