Skip to content

Commit

Permalink
varnishncsa: Take [BE]{Req,Resp}Unset into account
Browse files Browse the repository at this point in the history
Fixes: #3528
  • Loading branch information
walid-git committed Nov 7, 2024
1 parent 9a85ef9 commit 5f6107c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
21 changes: 17 additions & 4 deletions bin/varnishncsa/varnishncsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ frag_line(enum format_policy fp, const char *b, const char *e,

static void
process_hdr(enum format_policy fp, const struct watch_head *head, const char *b,
const char *e)
const char *e, int unset)
{
struct watch *w;
const char *p;
Expand All @@ -963,7 +963,12 @@ process_hdr(enum format_policy fp, const struct watch_head *head, const char *b,
CHECK_OBJ_NOTNULL(w, WATCH_MAGIC);
if (!isprefix(w->key, w->keylen, b, e, &p))
continue;
frag_line(fp, p, e, &w->frag);
if (unset) {
frag_line(fp, CTX.missing_string,
CTX.missing_string + strlen(CTX.missing_string),
&w->frag);
} else
frag_line(fp, p, e, &w->frag);
}
}

Expand Down Expand Up @@ -1098,7 +1103,7 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
break;
case SLT_BereqHeader:
case SLT_ReqHeader:
process_hdr(FMTPOL_REQ, &CTX.watch_reqhdr, b, e);
process_hdr(FMTPOL_REQ, &CTX.watch_reqhdr, b, e, 0);
if (ISPREFIX("Authorization:", b, e, &p) &&
ISPREFIX("basic ", p, e, &p))
frag_line(FMTPOL_REQ, p, e,
Expand All @@ -1110,7 +1115,15 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
break;
case SLT_BerespHeader:
case SLT_RespHeader:
process_hdr(FMTPOL_RESP, &CTX.watch_resphdr, b, e);
process_hdr(FMTPOL_RESP, &CTX.watch_resphdr, b, e, 0);
break;
case SLT_BereqUnset:
case SLT_ReqUnset:
process_hdr(FMTPOL_REQ, &CTX.watch_reqhdr, b, e, 1);
break;
case SLT_BerespUnset:
case SLT_RespUnset:
process_hdr(FMTPOL_RESP, &CTX.watch_resphdr, b, e, 1);
break;
case SLT_VCL_call:
if (!strcasecmp(b, "recv")) {
Expand Down
31 changes: 18 additions & 13 deletions bin/varnishtest/tests/u00020.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ varnish v1 -vcl+backend {
set bereq.method = "HEAD";
set bereq.url = "/vbf-url?q=vbfQuerry";
set bereq.http.Authorization = "basic dmJmOnBhc3M=";
unset bereq.http.unset;
}

sub vcl_backend_response {
set bereq.http.bereqhdr = "vbr-modified";
set bereq.http.notsent = "notsent";
set bereq.http.unset = "toolate";
set bereq.method = "CONNECT";
set bereq.url = "/vbr-url?q=vbrQuerry";
set bereq.http.Authorization = "basic dmJyOnBhc3M=";
Expand All @@ -28,15 +30,15 @@ varnish v1 -vcl+backend {


client c1 {
txreq -url "/client-url?q=clientQuerry" -hdr "bereqhdr: client-header" -hdr "Authorization:basic Y2xpZW50OnBhc3M="
txreq -url "/client-url?q=clientQuerry" -hdr "bereqhdr: client-header" -hdr "unset: client" -hdr "Authorization:basic Y2xpZW50OnBhc3M="
rxresp
} -run

shell {
varnishncsa -n ${v1_name} -d -b -F '%H %{bereqhdr}i %{notsent}i %m %q %U %u' > ncsa_sb.txt
varnishncsa -n ${v1_name} -d -b -F '%H %{bereqhdr}i %{notsent}i %{unset}i %m %q %U %u' > ncsa_sb.txt

cat >expected_sb.txt <<-EOF
HTTP/1.1 vbf-modified - HEAD ?q=vbfQuerry /vbf-url vbf
HTTP/1.1 vbf-modified - - HEAD ?q=vbfQuerry /vbf-url vbf
EOF
diff -u expected_sb.txt ncsa_sb.txt
}
Expand All @@ -47,14 +49,15 @@ varnish v1 -stop

server s1 {
rxreq
txresp -status 202 -hdr "beresp: origin"
txresp -status 202 -hdr "beresp: origin" -hdr "unset: origin"
} -start

varnish v1 -vcl+backend {

sub vcl_backend_response {
set beresp.http.beresp = "vbr-updated";
set beresp.status = 200;
unset beresp.http.unset;
}

} -start
Expand All @@ -67,10 +70,10 @@ client c1 {


shell {
varnishncsa -n ${v1_name} -d -b -F '%s %{beresp}o' > ncsa_rb.txt
varnishncsa -n ${v1_name} -d -b -F '%s %{beresp}o %{unset}o' > ncsa_rb.txt

cat >expected_rb.txt <<-EOF
202 origin
202 origin origin
EOF
diff -u expected_rb.txt ncsa_rb.txt
}
Expand All @@ -81,7 +84,7 @@ varnish v1 -stop

server s1 {
rxreq
txresp -status 202 -hdr "resp: origin"
txresp -status 202 -hdr "resp: origin" -hdr "unset: origin"
} -start

varnish v1 -vcl+backend {
Expand All @@ -95,6 +98,7 @@ varnish v1 -vcl+backend {
set resp.http.resp = "deliver-updated";
set resp.status = 201;
set resp.http.added = "deliver";
unset resp.http.unset;
}

} -start
Expand All @@ -106,10 +110,10 @@ client c1 {
} -run

shell {
varnishncsa -n ${v1_name} -d -c -F '%s %{resp}o %{added}o' > ncsa_sc.txt
varnishncsa -n ${v1_name} -d -c -F '%s %{resp}o %{unset}o %{added}o' > ncsa_sc.txt

cat >expected_sc.txt <<-EOF
201 deliver-updated deliver
201 deliver-updated - deliver
EOF
diff -u expected_sc.txt ncsa_sc.txt
}
Expand All @@ -131,6 +135,7 @@ varnish v1 -vcl+backend {
set req.url = "/recv-url?q=recvQuerry";
set req.http.Authorization = "basic cmVjdjpwYXNz";
set req.http.notreceived = "recv";
unset req.http.unset;
}

sub vcl_hash {
Expand All @@ -147,17 +152,17 @@ varnish v1 -vcl+backend {
client c1 {
txreq -req "POST" -url "/client-url?q=clientQuerry" \
-hdr "reqhdr: client-header" \
-hdr "Authorization:basic Y2xpZW50OnBhc3M="
-hdr "Authorization:basic Y2xpZW50OnBhc3M=" \
-hdr "unset: client"
rxresp
} -run


shell {
varnishncsa -n ${v1_name} -d -c -F '%H %{reqhdr}i %{notreceived}i %m %q %U %u' > ncsa_rc.txt
varnishncsa -n ${v1_name} -d -c -F '%H %{reqhdr}i %{notreceived}i %{unset}i %m %q %U %u' > ncsa_rc.txt

cat >expected_rc.txt <<-EOF
HTTP/1.1 client-header - POST ?q=clientQuerry /client-url client
HTTP/1.1 client-header - client POST ?q=clientQuerry /client-url client
EOF
diff -u expected_rc.txt ncsa_rc.txt
}
# TODO: Handle Unset

0 comments on commit 5f6107c

Please sign in to comment.