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

Expose the hash via {bereq,req}.hash

This is available after vcl_hash{}. Tests will follow.
parent 94490066
......@@ -30,12 +30,15 @@
*/
#include "config.h"
#include <stdio.h>
#include "cache.h"
#include "common/heritage.h"
#include "cache_director.h"
#include "vrt.h"
#include "vrt_obj.h"
#include "vsha256.h"
static char vrt_hostname[255] = "";
......@@ -761,6 +764,40 @@ VRT_BODY_L(resp)
/*--------------------------------------------------------------------*/
const char *
VRT_r_req_hash(VRT_CTX)
{
char *p;
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
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", ctx->req->digest[i]);
return (p);
}
const char *
VRT_r_bereq_hash(VRT_CTX)
{
char *p;
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
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", ctx->bo->digest[i]);
return (p);
}
/*--------------------------------------------------------------------*/
#define HTTP_VAR(x) \
struct http * \
VRT_r_##x(VRT_CTX) \
......
......@@ -41,9 +41,9 @@ varnish v1 -errvcl {Operator > not possible on BACKEND} {
sub vcl_recv { if (a > b) { } }
}
varnish v1 -errvcl {Symbol not found: 'req.hash' (expected type BOOL):} {
varnish v1 -errvcl {Symbol not found: 'req.foo' (expected type BOOL):} {
backend b { .host = "127.0.0.1"; }
sub vcl_hash { if (req.hash != "foo") { } }
sub vcl_hash { if (req.foo != "bar") { } }
}
varnish v1 -errvcl {Symbol not found: 'foo.bar'} {
......
......@@ -38,9 +38,9 @@ varnish v1 -errvcl {Expected ';' got 'if'} {
sub vcl_recv { set req.url = "foo" if "bar"; }
}
varnish v1 -errvcl {Symbol not found: 'req.hash' (expected type STRING_LIST):} {
varnish v1 -errvcl {Symbol not found: 'req.foo' (expected type STRING_LIST):} {
backend b { .host = "127.0.0.1"; }
sub vcl_hash { hash_data(req.hash); }
sub vcl_hash { hash_data(req.foo); }
}
varnish v1 -vcl {
......
......@@ -233,6 +233,13 @@ sp_variables = [
The request type (e.g. "GET", "HEAD").
"""
),
('req.hash',
'STRING',
('hit', 'miss', 'pass', 'purge', 'deliver', ),
(), """
The hash key of this request.
"""
),
('req.url',
'STRING',
('client',),
......@@ -418,6 +425,13 @@ sp_variables = [
The request body.
"""
),
('bereq.hash',
'STRING',
('pipe', 'backend', ),
(), """
The hash key of this request.
"""
),
('bereq.method',
'STRING',
('pipe', 'backend', ),
......
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