Varnish 3.0.2 req.hash
gau at gprj.net
gau at gprj.net
Sun Feb 12 03:38:32 CET 2012
Hi,
Hash is stored in the sp->digest(created after the vcl_hash has been
called.The current version)
To access it is necessary for VMOD
sample(""this code is no guarantee. no error check"")
VCC:
Function STRING gethash()
C:
const char * vmod_gethash(struct sess *sp){
int u = WS_Reserve(sp->wrk->ws, 0);
char *tmp = (char *)sp->wrk->ws->f;
for(int i = 0; i < DIGEST_LEN; i++)
sprintf(tmp + 2 * i, "%02x",sp->digest[i]);
WS_Release(sp->wrk->ws, DIGEST_LEN*2+1);
return tmp;
}
include list(It includes those that do not need)
#include <stdlib.h>
#include "vcl.h"
#include "vrt.h"
#include "bin/varnishd/cache.h"
#include "bin/varnishd/cache_backend.h"
#include "sys/socket.h"
#include "vcc_if.h"
#include <stdio.h>
#include <syslog.h>
#include "vsha256.h"
VCL:
import example2;// my test vmod
sub vcl_deliver{
set resp.http.X-HASH=example2.gethash();
}
TEST:
wget -d http://192.168.1.199:6081/test -O - > /dev/null
X-HASH: 4c77debfa66306c3b9d4ed17389bca9b4b0780ca2ebbef67104c28cb77c5995a
wget -d http://192.168.1.199:6081/test2 -O - > /dev/null
X-HASH: 759b213ba3e86f899a55243d31028240d3ee4680583f18356bfe6d37d43dff20
wget -d http://192.168.1.199:6081/test2XXXXXXXXXXXXXXXXXXXXXXXXXX
-O - > /dev/null
X-HASH: c79b81e7d55154585e80c03e954a7ccd8dcc067c8bd5d6b7d40d35276fd54a6d
about VMOD:
https://www.varnish-cache.org/docs/trunk/reference/vmod.html
and
https://github.com/varnish/libvmod-example
Hope this helps,
--
Syohei Tanaka(@xcir)
http://xcir.net/
(:3[__])
2012/2/12 Hugues Alary <hugues.alary at gmail.com>:
> Hi Syohey,
>
> Thanks for your answer.
>
> My final goal is to get the hash calculated by Varnish. In the documentation
> of the 3.0.2 version it is written that req.hash contains this hash. I guess
> they just forgot to remove it and that req.hash doesn't exist anymore.
>
> However, is there a mean to get the final hash calculated by varnish, the
> result of hash_data()?
>
> Here: https://www.varnish-cache.org/docs/trunk/phk/varnish_does_not_hash.html it
> is written:
>
>
> "All the strings hash_data() are fed, are pushed through a cryptographic
> hash algorithm called SHA256, which, as the name says, always spits out 256
> bits (= 32 bytes), no matter how many bits you feed it."
>
> And that's what I am looking for, the final value of the hash. I guess I
> could do it myself with a bit of C, but I would think that it is possible to
> get this value from somewhere since Varnish already does the calculation.
>
> -Hugues
>
> On Fri, Feb 10, 2012 at 5:22 PM, gau at gprj.net <gau at gprj.net> wrote:
>>
>> Hugues,
>>
>> req.hash is the original write-only.(If my memory serves me)
>> and, VCL is a notation has changed Varnish3.
>> req.hash is replaced to hash_data();
>>
>>
>> vcl:
>> sub vcl_hash {
>> hash_data(req.url);
>> set req.http.X-TEST = req.url; //add
>> if (req.http.host) {
>> hash_data(req.http.host);
>> set req.http.X-TEST = req.http.X-TEST + " + " + req.http.host;
>> //add
>> } else {
>> hash_data(server.ip);
>> set req.http.X-TEST = req.http.X-TEST + " + " + server.ip; //add
>> }
>> return (hash);
>> }
>>
>>
>> sub vcl_deliver{
>> set resp.http.X-TEST = req.http.X-TEST;
>> }
>>
>> test:
>> wget -d http://192.168.1.199:6081/test -O - > /dev/null
>>
>> X-TEST: /test + 192.168.1.199:6081
>>
>> Is not a very smart.
>> (Is not a hash, but understood what anything was used)
>>
>>
>> Can not think only about making the other VMOD.
>>
>>
>> --
>> Syohei Tanaka(@xcir)
>> http://xcir.net/
>>
>>
>>
>> 2012/2/11 Hugues Alary <hugues.alary at gmail.com>:
>> > 2012/2/10 Roberto O. Fernández Crisial
>> > <roberto.fernandezcrisial at gmail.com>
>> >>
>> >> Hugues,
>> >
>> >
>> > Hi Roberto,
>> >
>> > Thank you for your answer.
>> >
>> >>
>> >>
>> >> Try this:
>> >>
>> >> set req.http.X-TEST = req.hash;
>> >> set req.http.TEST = req.http.X-TEST;
>> >>
>> >> It should work.
>> >
>> >
>> >
>> > Unfortunately the problem doesn't come from the syntax of
>> > "req.http.TEST"
>> > but from req.hash. Here is the message:
>> >
>> > Message from VCC-compiler:
>> > Symbol not found: 'req.hash' (expected type STRING_LIST):
>> > ('input' Line 219 Pos 31)
>> > set req.http.X-TEST = req.hash;
>> > ------------------------------########-
>> >
>> > Running VCC-compiler failed, exit 1
>> >
>> > VCL compilation failed
>> >
>> >
>> > I also tried to put that in my configuration:
>> >
>> > set req.http.X-TEST = {""} + req.hash;
>> >
>> >
>> > And, same error:
>> >
>> > Message from VCC-compiler:
>> > Symbol not found: 'req.hash' (expected type STRING):
>> > ('input' Line 219 Pos 38)
>> > set req.http.X-TEST = {""} + req.hash;
>> > -------------------------------------########-
>> >
>> > Running VCC-compiler failed, exit 1
>> >
>> > VCL compilation failed
>> >
>> >
>> > Do you have any other idea ?
>> >
>> >>
>> >> Good luck,
>> >>
>> >> Roberto (@rofc)
>> >>
>> >
>> > Thanks!
>> > -Hugues
>> >
>> > _______________________________________________
>> > varnish-misc mailing list
>> > varnish-misc at varnish-cache.org
>> > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
>
>
>
> --
> Hugues ALARY
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
More information about the varnish-misc
mailing list