Skip to content

Commit 191be48

Browse files
committed
req: test our new ocstash's capability
1 parent 429e1e0 commit 191be48

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed

bin/varnishtest/tests/b00092.vtc

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ varnishtest "Use multiple objects for a single request"
22

33
server s0 {
44
rxreq
5-
txresp -hdr "method: O1_METHOD"
5+
txresp -hdr "method: O1_METHOD" -hdr "bodypart: head,"
66
rxreq
7-
txresp -hdr "url: /o2_url"
7+
txresp -hdr "url: /o2_url" -hdr "bodypart: arms,"
88
rxreq
9-
txresp -hdr "val: 3"
9+
txresp -hdr "val: 3" -body "all the rest"
1010
} -start
1111

1212

@@ -25,14 +25,17 @@ varnish v1 -vcl+backend {
2525
if (req.restarts == 0) {
2626
set req.method = resp.http.method;
2727
debug.log_strands("resp.http.method", resp.http.method);
28+
debug.body_prefix(resp.http.bodypart);
2829
} else if (req.restarts == 1) {
2930
set req.url = resp.http.url;
3031
debug.log_strands("resp.http.url", resp.http.url);
32+
debug.body_prefix(resp.http.bodypart);
3133
} else {
3234
set resp.http.method = req.method;
3335
set resp.http.url = req.url;
3436
debug.log_strands("req.method", req.method);
3537
debug.log_strands("req.url", req.url);
38+
set resp.filters = "debug.body_prefix";
3639
return (deliver);
3740
}
3841
return (restart);
@@ -45,4 +48,5 @@ client c1 {
4548
expect resp.http.method == O1_METHOD
4649
expect resp.http.url == /o2_url
4750
expect resp.http.val == 3
51+
expect resp.body == "head,arms,all the rest"
4852
} -run

vmod/vmod_debug.c

+29
Original file line numberDiff line numberDiff line change
@@ -1358,3 +1358,32 @@ xyzzy_log_strands(VRT_CTX, VCL_STRING prefix, VCL_STRANDS subject, VCL_INT nn)
13581358
ptr_where(ctx, p), p, n, p, strlen(p) > (unsigned)n ? "..." : "");
13591359
}
13601360
}
1361+
1362+
const void * const priv_task_id_bp = &priv_task_id_bp;
1363+
1364+
VCL_VOID
1365+
xyzzy_body_prefix(VRT_CTX, VCL_STRING s)
1366+
{
1367+
struct xyzzy_bp_string *bps;
1368+
struct xyzzy_bp *bp;
1369+
struct vmod_priv *task;
1370+
1371+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
1372+
1373+
task = VRT_priv_task(ctx, priv_task_id_bp);
1374+
AN(task);
1375+
bp = task->priv;
1376+
if (bp == NULL) {
1377+
bp = WS_Alloc(ctx->ws, (unsigned)sizeof *bp);
1378+
AN(bp);
1379+
task->priv = bp;
1380+
INIT_OBJ(bp, XYZZY_BP_MAGIC);
1381+
VSTAILQ_INIT(&bp->head);
1382+
}
1383+
CHECK_OBJ(bp, XYZZY_BP_MAGIC);
1384+
1385+
bps = WS_Alloc(ctx->ws, (unsigned)sizeof *bps);
1386+
AN(bps);
1387+
bps->s = s;
1388+
VSTAILQ_INSERT_TAIL(&bp->head, bps, list);
1389+
}

vmod/vmod_debug.h

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ debug_add_filters(VRT_CTX);
3434
void
3535
debug_remove_filters(VRT_CTX);
3636

37+
/* body_prefix vdp */
38+
struct xyzzy_bp_string {
39+
VSTAILQ_ENTRY(xyzzy_bp_string) list;
40+
VCL_STRING s;
41+
};
42+
43+
struct xyzzy_bp {
44+
unsigned magic;
45+
#define XYZZY_BP_MAGIC 0x88db5d93
46+
VSTAILQ_HEAD(,xyzzy_bp_string) head;
47+
};
48+
49+
extern const void * const priv_task_id_bp;
50+
3751
/* vmod_debug_transport_reembarking_http1.c */
3852
void
3953
debug_transport_reembarking_http1_use(VRT_CTX);

vmod/vmod_debug.vcc

+4
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ Example::
466466

467467
Debug c prefix[0]: (ws) 0x7fe69ef80420 abcd...
468468

469+
$Function VOID body_prefix(STRING)
470+
471+
Add this string to the prefix sent by the body_prefix filter
472+
469473
DEPRECATED
470474
==========
471475

vmod/vmod_debug_filters.c

+70
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,74 @@ static const struct vdp xyzzy_vdp_awshog = {
667667
.init = xyzzy_awshog_init
668668
};
669669

670+
/**********************************************************************/
671+
672+
static int v_matchproto_(vdp_init_f)
673+
xyzzy_vdp_body_prefix_init(VRT_CTX, struct vdp_ctx *vdc, void **priv)
674+
{
675+
struct xyzzy_bp_string *bps;
676+
struct xyzzy_bp *bp;
677+
struct vmod_priv *task;
678+
intmax_t l;
679+
680+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
681+
CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC);
682+
AN(vdc->clen);
683+
684+
task = VRT_priv_task_get(ctx, priv_task_id_bp);
685+
if (task == NULL)
686+
return (1);
687+
CAST_OBJ_NOTNULL(bp, task->priv, XYZZY_BP_MAGIC);
688+
AN(priv);
689+
AZ(*priv);
690+
*priv = bp;
691+
692+
if (*vdc->clen < 0)
693+
return (0);
694+
695+
l = 0;
696+
VSTAILQ_FOREACH(bps, &bp->head, list)
697+
l += strlen(bps->s);
698+
*vdc->clen += l;
699+
700+
return (0);
701+
}
702+
703+
static int v_matchproto_(vdp_bytes_f)
704+
xyzzy_vdp_body_prefix_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
705+
const void *ptr, ssize_t len)
706+
{
707+
struct xyzzy_bp_string *bps;
708+
struct xyzzy_bp *bp;
709+
710+
AN(priv);
711+
CAST_OBJ_NOTNULL(bp, *priv, XYZZY_BP_MAGIC);
712+
713+
while ((bps = VSTAILQ_FIRST(&bp->head)) != NULL) {
714+
VSTAILQ_REMOVE_HEAD(&bp->head, list);
715+
if (VDP_bytes(vdc, VDP_NULL, bps->s, strlen(bps->s)))
716+
return (vdc->retval);
717+
}
718+
719+
return (VDP_bytes(vdc, act, ptr, len));
720+
}
721+
722+
static int v_matchproto_(vdp_fini_f)
723+
xyzzy_vdp_body_prefix_fini(struct vdp_ctx *vdc, void **priv)
724+
{
725+
(void)vdc;
726+
AN(priv);
727+
*priv = NULL;
728+
return (0);
729+
}
730+
731+
static const struct vdp xyzzy_vdp_body_prefix = {
732+
.name = "debug.body_prefix",
733+
.init = xyzzy_vdp_body_prefix_init,
734+
.bytes = xyzzy_vdp_body_prefix_bytes,
735+
.fini = xyzzy_vdp_body_prefix_fini
736+
};
737+
670738
void
671739
debug_add_filters(VRT_CTX)
672740
{
@@ -677,6 +745,7 @@ debug_add_filters(VRT_CTX)
677745
AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chksha256));
678746
AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chkcrc32));
679747
AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_awshog));
748+
AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_body_prefix));
680749
}
681750

682751
void
@@ -689,4 +758,5 @@ debug_remove_filters(VRT_CTX)
689758
VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chksha256);
690759
VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chkcrc32);
691760
VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_awshog);
761+
VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_body_prefix);
692762
}

0 commit comments

Comments
 (0)