Commit eb34f7dd authored by Federico G. Schwindt's avatar Federico G. Schwindt

Turn {be}req.hash into a BLOB

Fixes #2402.
parent 09aa86a6
......@@ -768,34 +768,32 @@ VRT_BODY_L(resp)
/*--------------------------------------------------------------------*/
static const char *
vrt_hash(VRT_CTX, uint8_t *digest)
{
char *p;
int i;
p = WS_Alloc(ctx->ws, SHA256_LEN * 2 + 1);
if (p == NULL)
return (NULL);
for (i = 0; i < SHA256_LEN; i++)
sprintf(&p[i * 2], "%02x", digest[i]);
static struct vmod_priv *
vrt_do_blob(VRT_CTX, uint8_t *digest)
{
struct vmod_priv *p;
p = (void *)WS_Alloc(ctx->ws, sizeof *p);
AN(p);
memset(p, 0, sizeof *p);
p->len = DIGEST_LEN;
p->priv = WS_Copy(ctx->ws, digest, DIGEST_LEN);
return (p);
}
const char *
VCL_BLOB
VRT_r_req_hash(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (vrt_hash(ctx, ctx->req->digest));
return (vrt_do_blob(ctx, ctx->req->digest));
}
const char *
VCL_BLOB
VRT_r_bereq_hash(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
return (vrt_hash(ctx, ctx->bo->digest));
return (vrt_do_blob(ctx, ctx->bo->digest));
}
/*--------------------------------------------------------------------*/
......
......@@ -6,11 +6,12 @@ server s1 {
} -start
varnish v1 -vcl+backend {
import vtc;
sub vcl_backend_response {
set beresp.http.bereq_hash = bereq.hash;
set beresp.http.bereq_hash = vtc.blob2hex(bereq.hash);
}
sub vcl_deliver {
set resp.http.req_hash = req.hash;
set resp.http.req_hash = vtc.blob2hex(req.hash);
}
} -start
......
......@@ -220,15 +220,17 @@ varnish v1 -errvcl {Function returns VOID} {
varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} {
backend b { .host = "127.0.0.1"; }
import vtc;
sub vcl_recv {
set req.http.foo = req.hash;
set req.http.foo = vtc.blob2hex(req.hash);
}
}
varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} {
backend b { .host = "127.0.0.1"; }
import vtc;
sub vcl_hash {
set req.http.foo = req.hash;
set req.http.foo = vtc.blob2hex(req.hash);
}
}
......
......@@ -234,7 +234,7 @@ sp_variables = [
"""
),
('req.hash',
'STRING',
'BLOB',
('hit', 'miss', 'pass', 'purge', 'deliver', ),
(), """
The hash key of this request.
......@@ -428,7 +428,7 @@ sp_variables = [
"""
),
('bereq.hash',
'STRING',
'BLOB',
('pipe', 'backend', ),
(), """
The hash key of this request.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment