Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cosimo/varnish-accept-language
An experimental VCL extension to squash client Accept-Language headers
https://github.com/cosimo/varnish-accept-language
Last synced: 10 days ago
JSON representation
An experimental VCL extension to squash client Accept-Language headers
- Host: GitHub
- URL: https://github.com/cosimo/varnish-accept-language
- Owner: cosimo
- Created: 2010-01-22T09:39:21.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2015-12-20T21:09:53.000Z (almost 9 years ago)
- Last Synced: 2023-04-21T10:38:41.401Z (over 1 year ago)
- Language: Perl
- Homepage: http://www.streppone.it/cosimo/blog/2010/01/my-opera-front-page-caching-and-varnish-hacking/
- Size: 25.4 KB
- Stars: 41
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Varnish Accept-Language VCL
===========================Last updated: 03/11/2011
Cosimo Streppone
Opera Software ASAHere you will find a VCL config file for Varnish (http://varnish-cache.org)
This VCL allows you to normalize and filter all the incoming requests
Accept-Language headers and reduce them to just the languages your site supports.*** WARNING ***
This VCL consists of C code. Your Varnish might explode. YMMV.
Don't use it in production if you don't know what you're doing.
We are using it in production, but we _don't_ know what we're doing :).Why would you want this?
------------------------Your site supports English and Japanese languages.
Your client browsers will send every possible Accept-Language header on Earth.
If you enable "Vary: Accept-Language" on Varnish or on your backends,
the cache hit ratio will rapidly drop, because of the huge variations
in Accept-Language contents.With this VCL, the Accept-Language header will be "rewritten" to just
"en" or "ja", depending on your client settings. If no match occurs,
you can select a default language.The rewritten header is "X-Varnish-Accept-Language".
You can choose to put this header back in "Accept-Language" if you wish.
In this way, the normalization will be completely transparent.Requirements
------------- gcc, make
- a recent perl, with `prove'Instructions
-------------1) Run 'make' informing the list of languages your site supports
and the default fallback in the command line, e.g.make DEFAULT_LANGUAGE=en SUPPORTED_LANGUAGES="en ja pt pt-br"
2) Run 'make test'
You should see "All tests successful" at the end of the execution3) Install the generated accept-language.vcl in /etc/varnish/
4) At the top of your main VCL file, add the following line:
include "/etc/varnish/accept-language.vcl";
and then in your vcl_recv() add:
C{
vcl_rewrite_accept_language(sp);
}CThis will parse Accept-Language and insert the final language into the
"X-Varnish-Accept-Language" header (req.http.X-Varnish-Accept-Language).6) Restart Varnish
7) Cross your fingers
8) Profit !!