Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Copy Accept-Encoding normalisation from EC2 Varnish #379

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

samsimpson1
Copy link
Member

@samsimpson1 samsimpson1 commented May 16, 2022

This is copied from the EC2-based Varnish config. This is required for replatforming work, since we will be retiring the EC2-based Varnish services.

I have tested it using Fastly Fiddle.

This is integration-only at this point to test before deploying everywhere.

Trello: https://trello.com/c/88bU7Qmm/854-normalise-accept-encoding-header-at-fastly

@@ -202,6 +202,22 @@ sub vcl_recv {
}
<% end %>

# Normalise Accept-Encoding header
Copy link
Contributor

Choose a reason for hiding this comment

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

Fastly already does some similar-looking stuff as standard - have you checked that this isn't replicating the snippet that Fastly adds itself? (if you view the full VCL in the Fastly UI, you should see an extra stanza or two of VCL that isn't coming from our templates - I think it's in there).

https://developer.fastly.com/reference/http/http-headers/Accept-Encoding/#normalization

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I wasn't aware of that. We can keep the bit that strips the header if the content is already compressed, but I don't know if that's worth bothering with

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry - I was partly mistaken - the config I was thinking of is actually ours.

Leads me to another question though, which is: have you tested that this doesn't break Brotli?

Copy link
Contributor

Choose a reason for hiding this comment

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

I still have a hunch that we're duplicating Fastly functionality but I'm less sure. It's important that we don't break Brotli though, since that would be a regression.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry yes, this does seem to be replicating what fastly is already doing. I copied this directly from the EC2 Varnish VCL file, so we can definitely get rid of the bits that check for gzip and deflate. We can probably keep the bit that checks if the content is already compressed, though.

The config that I copied and that which Fastly already does shouldn't work with brotli at all, but it shouldn't break anything. We're manipulating a request header here before it gets to a backend server that performs the compression, so if a browser says it accepts brotli, the server will never see that and will only serve an uncompressed file or one done with gzip/deflate

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, are you saying the Brotli support has never worked? 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell, that should never have worked because an Accept-Encoding: br header would be stripped out in EC2's Varnish: https://github.com/alphagov/govuk-puppet/blob/56c3da336aadb68d7dfbf6b0db2e748b18221bbc/modules/varnish/templates/default.vcl.erb#L49-L63

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this PR to only remove the Accept-Encoding header if the content is already compressed. The functionality Fastly provides should do the rest.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure Brotli worked before. https://trello.com/c/u9qiWQr1/13-3-enable-brotli-compression-in-fastly-for-production

Bear in mind that it's Fastly that serves the Brotli-compressed objects, not us. So as long as we're not breaking the header in vcl_recv (i.e. the procedure that runs before Fastly processes the incoming request) we should be ok. Please do test that we haven't broken it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually now I'm not sure that I'm not just getting confused here. Anyway, please test for regressions! Code looks good to me.

@samsimpson1 samsimpson1 force-pushed the header_normalise branch 2 times, most recently from 691b6dd to a3e7619 Compare May 19, 2022 08:42
Copy link
Contributor

@sengi sengi left a comment

Choose a reason for hiding this comment

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

LGTM (chatted out of band about it being integration-only - that's fine if you wanna do separate PRs to roll it out the rest of the way)

@samsimpson1 samsimpson1 merged commit ee2bf89 into main Jul 7, 2022
@samsimpson1 samsimpson1 deleted the header_normalise branch July 7, 2022 08:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants