Commit 1b57f4cb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Add a VCC variable type "HTTP" to refer to an entire

HTTP message.  Presently supported "req", "bereq", "resp", "beresp".
parent 92004db2
......@@ -608,3 +608,19 @@ VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
return (ctx->req->obj->objcore->flags & OC_F_PASS ? 1 : 0);
}
/*--------------------------------------------------------------------*/
#define HTTP_VAR(x) \
struct http * \
VRT_r_##x(const struct vrt_ctx *ctx) \
{ \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->http_##x, HTTP_MAGIC); \
return (ctx->http_##x); \
}
HTTP_VAR(req)
HTTP_VAR(resp)
HTTP_VAR(bereq)
HTTP_VAR(beresp)
......@@ -2,6 +2,7 @@ varnishtest "Test std & debug vmod"
server s1 {
rxreq
expect req.http.encrypted == "ROT52"
txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4
} -start
......@@ -9,6 +10,10 @@ varnish v1 -vcl+backend {
import ${vmod_std};
import ${vmod_debug};
sub vcl_recv {
debug.rot52(req);
}
sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar);
......@@ -17,6 +22,7 @@ varnish v1 -vcl+backend {
debug.test_priv_vcl();
std.log("VCL initiated log");
std.syslog(8 + 7, "Somebody runs varnishtest");
debug.rot52(resp);
}
} -start
......@@ -27,6 +33,7 @@ client c1 {
expect resp.bodylen == "4"
expect resp.http.foo == "BAR"
expect resp.http.bar == "foo"
expect resp.http.encrypted == "ROT52"
} -run
varnish v1 -errvcl {Wrong enum value. Expected one of:} {
......
......@@ -41,7 +41,7 @@
#define VRT_MAJOR_VERSION 1U
#define VRT_MINOR_VERSION 1U
#define VRT_MINOR_VERSION 2U
/***********************************************************************/
......@@ -59,21 +59,23 @@ struct suckaddr;
/***********************************************************************
* This is the central definition of the mapping from VCL types to
* C-types. The python scripts read these from here.
* (alphabetic order)
*/
typedef struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef unsigned VCL_BOOL;
typedef double VCL_BYTES;
typedef double VCL_DURATION;
typedef const char * VCL_ENUM;
typedef const struct gethdr_s * VCL_HEADER;
typedef struct http * VCL_HTTP;
typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP;
typedef double VCL_REAL;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
typedef void VCL_VOID;
typedef const struct vmod_priv * VCL_BLOB;
/***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT
......
......@@ -197,6 +197,13 @@ sp_variables = [
specified by the -n parameter.
"""
),
('req',
'HTTP',
( 'client',),
( ), """
The entire request HTTP data structure
"""
),
('req.method',
'STRING',
( 'client',),
......@@ -294,6 +301,13 @@ sp_variables = [
always (re)fetch from the backend.
"""
),
('bereq',
'HTTP',
( 'backend',),
( ), """
The entire backend request HTTP data structure
"""
),
('bereq.xid',
'STRING',
( 'backend',),
......@@ -370,6 +384,13 @@ sp_variables = [
backend. Not available in pipe mode.
"""
),
('beresp',
'HTTP',
( 'backend_response', 'backend_error'),
( ), """
The entire backend response HTTP data structure
"""
),
('beresp.proto',
'STRING',
( 'backend_response', 'backend_error'),
......@@ -553,6 +574,13 @@ sp_variables = [
( ), """
"""
),
('resp',
'HTTP',
( 'deliver', 'synth'),
( ), """
The entire response HTTP data structure
"""
),
('resp.proto',
'STRING',
( 'deliver', 'synth', ),
......@@ -597,17 +625,17 @@ aliases = [
stv_variables = (
('free_space', 'BYTES', "0.", 'storage.<name>.free_space', """
Free space available in the named stevedore. Only available for
the malloc stevedore.
"""),
Free space available in the named stevedore. Only available for
the malloc stevedore.
"""),
('used_space', 'BYTES', "0.", 'storage.<name>.used_space', """
Used space in the named stevedore. Only available for the malloc
stevedore.
"""),
Used space in the named stevedore. Only available for the malloc
stevedore.
"""),
('happy', 'BOOL', "0", 'storage.<name>.happy', """
Health status for the named stevedore. Not available in any of the
current stevedores.
"""),
Health status for the named stevedore. Not available in any of the
current stevedores.
"""),
)
#######################################################################
......@@ -1188,11 +1216,11 @@ hdr="storage"
fp_vclvar.write("\n" + hdr + "\n");
fp_vclvar.write("~" * len(hdr) + "\n");
for i in stv_variables:
fp_vclvar.write("\n" + i[3] + "\n\n")
fp_vclvar.write("\tType: " + i[1] + "\n\n")
fp_vclvar.write("\tReadable from: client, backend\n\n")
for j in i[4].split("\n"):
fp_vclvar.write("\t%s\n" % j.strip())
fp_vclvar.write("\n" + i[3] + "\n\n")
fp_vclvar.write("\tType: " + i[1] + "\n\n")
fp_vclvar.write("\tReadable from: client, backend\n\n")
for j in i[4].split("\n"):
fp_vclvar.write("\t%s\n" % j.strip())
fp_vclvar.close()
......@@ -47,10 +47,12 @@ from pprint import pprint, pformat
ctypes = {
'BACKEND': "VCL_BACKEND",
'BLOB': "VCL_BLOB",
'BOOL': "VCL_BOOL",
'DURATION': "VCL_DURATION",
'ENUM': "VCL_ENUM",
'HEADER': "VCL_HEADER",
'HTTP': "VCL_HTTP",
'INT': "VCL_INT",
'IP': "VCL_IP",
'PRIV_CALL': "struct vmod_priv *",
......@@ -60,7 +62,6 @@ ctypes = {
'STRING_LIST': "const char *, ...",
'TIME': "VCL_TIME",
'VOID': "VCL_VOID",
'BLOB': "VCL_BLOB",
}
#######################################################################
......
......@@ -80,3 +80,8 @@ Foo indeed.
$Method TIME .date()
You never know when you need a date.
$Function VOID rot52(HTTP)
Encrypt the HTTP header with quad-ROT13 encryption,
(this is approx 33% better than triple-DES).
......@@ -138,3 +138,12 @@ vmod_no_backend(const struct vrt_ctx *ctx)
return (NULL);
}
VCL_VOID __match_proto__(td_debug_rot52)
vmod_rot52(const struct vrt_ctx *ctx, VCL_HTTP hp)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
http_PrintfHeader(hp, "Encrypted: ROT52");
}
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