[4.0] cf33308 vcl_hash() returns lookup now
Federico G. Schwindt
fgsch at lodoss.net
Tue Jun 24 11:31:37 CEST 2014
commit cf333085ae42d8b3f39707a55fca6b51435fec1c
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Fri Apr 11 19:24:51 2014 +0100
vcl_hash() returns lookup now
While here fmt(1) the text.
diff --git a/doc/sphinx/users-guide/vcl-hashing.rst b/doc/sphinx/users-guide/vcl-hashing.rst
index 83758ad..bdc47b0 100644
--- a/doc/sphinx/users-guide/vcl-hashing.rst
+++ b/doc/sphinx/users-guide/vcl-hashing.rst
@@ -1,25 +1,25 @@
Hashing
-------
-Internally, when Varnish stores content in the cache it stores the object together with a hash
-key to find the object again. In the default setup this key is
-calculated based on the content of the *Host* header or the IP address
-of the server and the URL.
+Internally, when Varnish stores content in the cache it stores the object
+together with a hash key to find the object again. In the default setup
+this key is calculated based on the content of the *Host* header or the
+IP address of the server and the URL.
Behold the `default vcl`::
- sub vcl_hash {
- hash_data(req.url);
- if (req.http.host) {
- hash_data(req.http.host);
- } else {
- hash_data(server.ip);
- }
- return (hash);
- }
-
-As you can see it first checks in `req.url` then `req.http.host` if it
-exists. It is worth pointing out that Varnish doesn't lowercase the
+ sub vcl_hash {
+ hash_data(req.url);
+ if (req.http.host) {
+ hash_data(req.http.host);
+ } else {
+ hash_data(server.ip);
+ }
+ return (lookup);
+ }
+
+As you can see it first checks in `req.url` then `req.http.host` if
+it exists. It is worth pointing out that Varnish doesn't lowercase the
hostname or the URL before hashing it so in theory having "Varnish.org/"
and "varnish.org/" would result in different cache entries. Browsers
however, tend to lowercase hostnames.
@@ -29,22 +29,20 @@ serve up different content to different clients based on arbitrary
criteria.
Let's say you want to serve pages in different languages to your users
-based on where their IP address is located. You would need some Vmod
-to get a country code and then put it into the hash. It might look
-like this.
+based on where their IP address is located. You would need some Vmod to
+get a country code and then put it into the hash. It might look like this.
In `vcl_recv`::
- set req.http.X-Country-Code = geoip.lookup(client.ip);
+ set req.http.X-Country-Code = geoip.lookup(client.ip);
And then add a `vcl_hash`::
- sub vcl_hash {
- hash_data(req.http.X-Country-Code);
- }
+ sub vcl_hash {
+ hash_data(req.http.X-Country-Code);
+ }
-As the default VCL will take care of adding the host and URL to the
-hash we don't have to do anything else. Be careful calling
-``return(hash)`` as this will abort the execution of the default VCL and
-Varnish can end up returning data based on
-more or less random inputs.
+As the default VCL will take care of adding the host and URL to the hash
+we don't have to do anything else. Be careful calling ``return (lookup)``
+as this will abort the execution of the default VCL and Varnish can end
+up returning data based on more or less random inputs.
More information about the varnish-commit
mailing list