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

Add bereq.body

Only available in vcl_backend_fetch{}. If it is unset varnish will not
pass the request body to the backend.

This is in preparation for addressing #1927.
parent 83c5ead8
......@@ -408,6 +408,21 @@ VRT_r_beresp_backend(VRT_CTX)
/*--------------------------------------------------------------------*/
void
VRT_l_bereq_body(VRT_CTX, const char *p, ...)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
assert(p == vrt_magic_string_unset);
if (ctx->bo->req != NULL) {
CHECK_OBJ_NOTNULL(ctx->bo->req, REQ_MAGIC);
ctx->bo->req = NULL;
http_Unset(ctx->bo->bereq, H_Content_Length);
}
}
/*--------------------------------------------------------------------*/
void
VRT_l_req_esi(VRT_CTX, unsigned process_esi)
{
......
......@@ -67,11 +67,16 @@ varnish v1 -errvcl {Symbol not found: 'mu' (expected type BOOL):} {
sub vcl_backend_response { set beresp.do_gzip = mu; }
}
varnish v1 -errvcl {Only HTTP header variables can be unset.} {
varnish v1 -errvcl {Only bereq.body and HTTP header variables can be unset.} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_response { unset beresp.do_gzip; }
}
varnish v1 -errvcl {bereq.body cannot be set.} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_fetch { set bereq.body = "foo"; }
}
varnish v1 -errvcl {Unknown token '<<' when looking for STRING} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { ban (<<); }
......
......@@ -83,6 +83,7 @@ struct ws;
typedef const struct vrt_acl * VCL_ACL;
typedef const struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef const char * VCL_BODY;
typedef unsigned VCL_BOOL;
typedef long long VCL_BYTES;
typedef double VCL_DURATION;
......
......@@ -381,6 +381,13 @@ sp_variables = [
This is the backend or director we attempt to fetch from.
"""
),
('bereq.body',
'BODY',
(),
('backend_fetch',), """
The request body.
"""
),
('bereq.method',
'STRING',
('pipe', 'backend', ),
......@@ -1164,7 +1171,7 @@ def one_var(nm, spec):
fo.write('\t "VRT_l_%s(ctx, ",\n' % cnam)
if nm == i[0]:
fh.write("void VRT_l_%s(VRT_CTX, " % cnam)
if typ != "STRING":
if typ != "STRING" and typ != "BODY":
fh.write("VCL_" + typ + ");\n")
else:
fh.write(ctyp + ", ...);\n")
......
......@@ -91,6 +91,11 @@ parse_set(struct vcc *tl)
sym = vcc_FindVar(tl, tl->t, 1, "cannot be set");
ERRCHK(tl);
assert(sym != NULL);
if (vcc_IdIs(tl->t, "bereq.body")) {
VSB_printf(tl->sb, "bereq.body cannot be set.\n");
vcc_ErrWhere(tl, tl->t);
return;
}
Fb(tl, 1, "%s\n", sym->lname);
tl->indent += INDENT;
vcc_NextToken(tl);
......@@ -132,9 +137,10 @@ parse_unset(struct vcc *tl)
sym = vcc_FindVar(tl, tl->t, 1, "cannot be unset");
ERRCHK(tl);
assert(sym != NULL);
if (sym->fmt != HEADER) {
if (sym->fmt != HEADER && !vcc_IdIs(tl->t, "bereq.body")) {
VSB_printf(tl->sb,
"Only HTTP header variables can be unset.\n");
"Only bereq.body and HTTP header variables can"
" be unset.\n");
vcc_ErrWhere(tl, tl->t);
return;
}
......
......@@ -54,6 +54,11 @@ const struct type BLOB[1] = {{
.name = "BLOB",
}};
const struct type BODY[1] = {{
.magic = 0xfae932d9,
.name = "BODY",
}};
const struct type BOOL[1] = {{
.magic = 0xfae932d9,
.name = "BOOL",
......
......@@ -53,6 +53,7 @@ ctypes = {
'ACL': "VCL_ACL",
'BACKEND': "VCL_BACKEND",
'BLOB': "VCL_BLOB",
'BODY': "VCL_BODY",
'BOOL': "VCL_BOOL",
'BYTES': "VCL_BYTES",
'DURATION': "VCL_DURATION",
......
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