Adjust to VDP API Changes from VC#4035

Ref https://github.com/varnishcache/varnish-cache/pull/4035
parent 3ddeaa5f
......@@ -204,14 +204,14 @@ VOID xvdp.arg(STRING)
The ``.arg()`` method sets a command-line argument to be used with a
program.
Restricted to: ``vcl_init``, ``vcl_deliver``.
Restricted to: ``vcl_init``, ``vcl_deliver``, ``vcl_backend_fetch``.
Invocations of ``.arg()`` in ``vcl_init`` set arguments to be used
globally in the VCL instance. Invocations in ``vcl_deliver`` set
arguments to be used for a single client response, overriding any
arguments that may have been set in ``vcl_init`` For example, you can
call ``.arg()`` in ``vcl_deliver`` if the arguments to be used are not
known until runtime.
globally in the VCL instance. Invocations in ``vcl_deliver`` /
``vcl_backend_fetch`` are valid for a single resp.body / bereq.body,
overriding any arguments that may have been set in ``vcl_init`` For
example, you can call ``.arg()`` in ``vcl_deliver`` if the arguments
to be used are not known until runtime.
The parameter in ``.arg()`` MAY be empty (if you need the empty string
as a CLI argument), but MAY NOT be NULL (for example, it may not be
......@@ -277,12 +277,12 @@ VOID xvdp.setenv(STRING var, STRING value, BOOL overwrite)
Set the environment variable ``var`` to ``value`` in the invoked
process.
Restricted to: ``vcl_init``, ``vcl_deliver``.
Restricted to: ``vcl_init``, ``vcl_deliver``, ``vcl_backend_fetch``.
Settings in ``vcl_init`` are global for the VCL instance, while
settings in ``vcl_deliver`` are valid for a single client response
(for use cases where the environment settings are not known until
runtime).
settings in ``vcl_deliver`` / ``vcl_backend_fetch`` are valid for a
single resp.body / bereq.body (for use cases where the environment
settings are not known until runtime).
Currently, any invocation of ``.setenv()`` in ``vcl_deliver`` cancels
all environment settings specified in ``vcl_init`` for the current
......
......@@ -174,9 +174,10 @@ mk_dup(int oldfd, int newfd)
}
static int v_matchproto_(vdp_init_f)
vdp_init(VRT_CTX, struct vdp_ctx *vc, void **priv, struct objcore *objcore)
vdp_init(VRT_CTX, struct vdp_ctx *vc, void **priv,
struct objcore *objcore, struct req *req,
struct http *hd, intmax_t *cl)
{
struct req *req;
struct vdp_state *state;
struct vdp_entry *vdpe;
struct vdp_map map_entry, *map;
......@@ -188,18 +189,19 @@ vdp_init(VRT_CTX, struct vdp_ctx *vc, void **priv, struct objcore *objcore)
char **argv;
CHECK_OBJ_NOTNULL(vc, VDP_CTX_MAGIC);
req = vc->req;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
AN(req->vcl);
AN(priv);
AZ(*priv);
CHECK_OBJ_ORNULL(objcore, OBJCORE_MAGIC);
CHECK_OBJ_ORNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(hd, HTTP_MAGIC);
AN(cl);
AZ(*priv);
vdpe = VTAILQ_LAST(&vc->vdp, vdp_entry_s);
CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
AN(vdpe->vdp);
map_entry.vdp = vdpe->vdp;
map_entry.vcl = req->vcl;
map_entry.vcl = ctx->vcl;
map = VRBT_FIND(vdp_tree, &tree_h, &map_entry);
CHECK_OBJ_NOTNULL(map, PIPE_VDP_MAP_MAGIC);
CHECK_OBJ_NOTNULL(map->obj, PIPE_VDP_MAGIC);
......@@ -309,7 +311,8 @@ vdp_init(VRT_CTX, struct vdp_ctx *vc, void **priv, struct objcore *objcore)
state->fds[STDIN_FILENO].fd = in[1];
state->fds[STDOUT_FILENO].fd = out[0];
state->fds[STDERR_FILENO].fd = err[0];
http_Unset(req->resp, H_Content_Length);
http_Unset(hd, H_Content_Length);
*cl = -1;
return (0);
}
......@@ -800,6 +803,9 @@ get_task(VRT_CTX, struct VPFX(pipe_vdp) *obj, const char *method)
return (task);
}
#define VDP_VALID_METHOD \
(VCL_MET_INIT | VCL_MET_DELIVER | VCL_MET_BACKEND_FETCH)
VCL_VOID
vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
{
......@@ -810,7 +816,7 @@ vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(obj, PIPE_VDP_MAGIC);
AN(ctx->method & (VCL_MET_INIT | VCL_MET_DELIVER));
AN(ctx->method & VDP_VALID_METHOD);
if (arg == NULL) {
VDPFAIL(ctx, "%s.arg(): arg is NULL", obj->name);
......@@ -893,7 +899,7 @@ vmod_vdp_setenv(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING var,
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(obj, PIPE_VDP_MAGIC);
AN(ctx->method & (VCL_MET_INIT | VCL_MET_DELIVER));
AN(ctx->method & VDP_VALID_METHOD);
if (var == NULL || *var == '\0') {
VDPFAIL(ctx, "%s.setenv(): var is empty", obj->name);
......
......@@ -185,14 +185,14 @@ $Method VOID .arg(STRING)
The ``.arg()`` method sets a command-line argument to be used with a
program.
$Restrict vcl_init vcl_deliver
$Restrict vcl_init vcl_deliver vcl_backend_fetch
Invocations of ``.arg()`` in ``vcl_init`` set arguments to be used
globally in the VCL instance. Invocations in ``vcl_deliver`` set
arguments to be used for a single client response, overriding any
arguments that may have been set in ``vcl_init`` For example, you can
call ``.arg()`` in ``vcl_deliver`` if the arguments to be used are not
known until runtime.
globally in the VCL instance. Invocations in ``vcl_deliver`` /
``vcl_backend_fetch`` are valid for a single resp.body / bereq.body,
overriding any arguments that may have been set in ``vcl_init`` For
example, you can call ``.arg()`` in ``vcl_deliver`` if the arguments
to be used are not known until runtime.
The parameter in ``.arg()`` MAY be empty (if you need the empty string
as a CLI argument), but MAY NOT be NULL (for example, it may not be
......@@ -251,12 +251,12 @@ $Method VOID .setenv(STRING var, STRING value, BOOL overwrite=1)
Set the environment variable ``var`` to ``value`` in the invoked
process.
$Restrict vcl_init vcl_deliver
$Restrict vcl_init vcl_deliver vcl_backend_fetch
Settings in ``vcl_init`` are global for the VCL instance, while
settings in ``vcl_deliver`` are valid for a single client response
(for use cases where the environment settings are not known until
runtime).
settings in ``vcl_deliver`` / ``vcl_backend_fetch`` are valid for a
single resp.body / bereq.body (for use cases where the environment
settings are not known until runtime).
Currently, any invocation of ``.setenv()`` in ``vcl_deliver`` cancels
all environment settings specified in ``vcl_init`` for the current
......
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