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) ...@@ -608,3 +608,19 @@ VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
return (ctx->req->obj->objcore->flags & OC_F_PASS ? 1 : 0); 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" ...@@ -2,6 +2,7 @@ varnishtest "Test std & debug vmod"
server s1 { server s1 {
rxreq rxreq
expect req.http.encrypted == "ROT52"
txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4 txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4
} -start } -start
...@@ -9,6 +10,10 @@ varnish v1 -vcl+backend { ...@@ -9,6 +10,10 @@ varnish v1 -vcl+backend {
import ${vmod_std}; import ${vmod_std};
import ${vmod_debug}; import ${vmod_debug};
sub vcl_recv {
debug.rot52(req);
}
sub vcl_deliver { sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo); set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar); set resp.http.bar = std.tolower(resp.http.bar);
...@@ -17,6 +22,7 @@ varnish v1 -vcl+backend { ...@@ -17,6 +22,7 @@ varnish v1 -vcl+backend {
debug.test_priv_vcl(); debug.test_priv_vcl();
std.log("VCL initiated log"); std.log("VCL initiated log");
std.syslog(8 + 7, "Somebody runs varnishtest"); std.syslog(8 + 7, "Somebody runs varnishtest");
debug.rot52(resp);
} }
} -start } -start
...@@ -27,6 +33,7 @@ client c1 { ...@@ -27,6 +33,7 @@ client c1 {
expect resp.bodylen == "4" expect resp.bodylen == "4"
expect resp.http.foo == "BAR" expect resp.http.foo == "BAR"
expect resp.http.bar == "foo" expect resp.http.bar == "foo"
expect resp.http.encrypted == "ROT52"
} -run } -run
varnish v1 -errvcl {Wrong enum value. Expected one of:} { varnish v1 -errvcl {Wrong enum value. Expected one of:} {
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define VRT_MAJOR_VERSION 1U #define VRT_MAJOR_VERSION 1U
#define VRT_MINOR_VERSION 1U #define VRT_MINOR_VERSION 2U
/***********************************************************************/ /***********************************************************************/
...@@ -59,21 +59,23 @@ struct suckaddr; ...@@ -59,21 +59,23 @@ struct suckaddr;
/*********************************************************************** /***********************************************************************
* This is the central definition of the mapping from VCL types to * This is the central definition of the mapping from VCL types to
* C-types. The python scripts read these from here. * C-types. The python scripts read these from here.
* (alphabetic order)
*/ */
typedef struct director * VCL_BACKEND; typedef struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef unsigned VCL_BOOL; typedef unsigned VCL_BOOL;
typedef double VCL_BYTES; typedef double VCL_BYTES;
typedef double VCL_DURATION; typedef double VCL_DURATION;
typedef const char * VCL_ENUM; typedef const char * VCL_ENUM;
typedef const struct gethdr_s * VCL_HEADER; typedef const struct gethdr_s * VCL_HEADER;
typedef struct http * VCL_HTTP;
typedef long VCL_INT; typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP; typedef const struct suckaddr * VCL_IP;
typedef double VCL_REAL; typedef double VCL_REAL;
typedef const char * VCL_STRING; typedef const char * VCL_STRING;
typedef double VCL_TIME; typedef double VCL_TIME;
typedef void VCL_VOID; typedef void VCL_VOID;
typedef const struct vmod_priv * VCL_BLOB;
/*********************************************************************** /***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT * This is the composite argument we pass to compiled VCL and VRT
......
...@@ -197,6 +197,13 @@ sp_variables = [ ...@@ -197,6 +197,13 @@ sp_variables = [
specified by the -n parameter. specified by the -n parameter.
""" """
), ),
('req',
'HTTP',
( 'client',),
( ), """
The entire request HTTP data structure
"""
),
('req.method', ('req.method',
'STRING', 'STRING',
( 'client',), ( 'client',),
...@@ -294,6 +301,13 @@ sp_variables = [ ...@@ -294,6 +301,13 @@ sp_variables = [
always (re)fetch from the backend. always (re)fetch from the backend.
""" """
), ),
('bereq',
'HTTP',
( 'backend',),
( ), """
The entire backend request HTTP data structure
"""
),
('bereq.xid', ('bereq.xid',
'STRING', 'STRING',
( 'backend',), ( 'backend',),
...@@ -370,6 +384,13 @@ sp_variables = [ ...@@ -370,6 +384,13 @@ sp_variables = [
backend. Not available in pipe mode. backend. Not available in pipe mode.
""" """
), ),
('beresp',
'HTTP',
( 'backend_response', 'backend_error'),
( ), """
The entire backend response HTTP data structure
"""
),
('beresp.proto', ('beresp.proto',
'STRING', 'STRING',
( 'backend_response', 'backend_error'), ( 'backend_response', 'backend_error'),
...@@ -553,6 +574,13 @@ sp_variables = [ ...@@ -553,6 +574,13 @@ sp_variables = [
( ), """ ( ), """
""" """
), ),
('resp',
'HTTP',
( 'deliver', 'synth'),
( ), """
The entire response HTTP data structure
"""
),
('resp.proto', ('resp.proto',
'STRING', 'STRING',
( 'deliver', 'synth', ), ( 'deliver', 'synth', ),
......
...@@ -47,10 +47,12 @@ from pprint import pprint, pformat ...@@ -47,10 +47,12 @@ from pprint import pprint, pformat
ctypes = { ctypes = {
'BACKEND': "VCL_BACKEND", 'BACKEND': "VCL_BACKEND",
'BLOB': "VCL_BLOB",
'BOOL': "VCL_BOOL", 'BOOL': "VCL_BOOL",
'DURATION': "VCL_DURATION", 'DURATION': "VCL_DURATION",
'ENUM': "VCL_ENUM", 'ENUM': "VCL_ENUM",
'HEADER': "VCL_HEADER", 'HEADER': "VCL_HEADER",
'HTTP': "VCL_HTTP",
'INT': "VCL_INT", 'INT': "VCL_INT",
'IP': "VCL_IP", 'IP': "VCL_IP",
'PRIV_CALL': "struct vmod_priv *", 'PRIV_CALL': "struct vmod_priv *",
...@@ -60,7 +62,6 @@ ctypes = { ...@@ -60,7 +62,6 @@ ctypes = {
'STRING_LIST': "const char *, ...", 'STRING_LIST': "const char *, ...",
'TIME': "VCL_TIME", 'TIME': "VCL_TIME",
'VOID': "VCL_VOID", 'VOID': "VCL_VOID",
'BLOB': "VCL_BLOB",
} }
####################################################################### #######################################################################
......
...@@ -80,3 +80,8 @@ Foo indeed. ...@@ -80,3 +80,8 @@ Foo indeed.
$Method TIME .date() $Method TIME .date()
You never know when you need a 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) ...@@ -138,3 +138,12 @@ vmod_no_backend(const struct vrt_ctx *ctx)
return (NULL); 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