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