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 Oct 11, 2024
1 parent 7468e9a commit b6c21ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
23 changes: 19 additions & 4 deletions bin/varnishncsa/varnishncsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ frag_line(enum update_mode um, const char *b, const char *e, struct fragment *f)

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

Expand Down Expand Up @@ -1087,7 +1092,7 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
case SLT_BereqHeader:
case SLT_ReqHeader:
process_hdr(&CTX.watch_reqhdr, b, e,
UPDATE_REQ(CTX));
UPDATE_REQ(CTX), 0);
if (ISPREFIX("Authorization:", b, e, &p) &&
ISPREFIX("basic ", p, e, &p))
frag_line(UPDATE_REQ(CTX), p, e,
Expand All @@ -1100,7 +1105,17 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
case SLT_BerespHeader:
case SLT_RespHeader:
process_hdr(&CTX.watch_resphdr, b, e,
UPDATE_RESP(CTX));
UPDATE_RESP(CTX), 0);
break;
case SLT_BereqUnset:
case SLT_ReqUnset:
process_hdr(&CTX.watch_reqhdr, b, e,
UPDATE_REQ(CTX), 1);
break;
case SLT_BerespUnset:
case SLT_RespUnset:
process_hdr(&CTX.watch_resphdr, b, e,
UPDATE_RESP(CTX), 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 b6c21ef

Please sign in to comment.