Commit 2d465b13 authored by Nils Goroll's avatar Nils Goroll

add some vcl which _almost_ works for removing elements from headers

parent 8dbfc85c
# looks like -*- vcl -*-
varnishtest "use case of suball() to remove header values"
varnish v1 -vcl {
import ${vmod_re2};
import std;
backend be { .host = "${bad_ip}"; }
sub vcl_init {
# \b is insufficient for the ,<remove> case:
# for AB-C removes only AB
new blacklist = re2.regex(
regsub(
"A|AB|ABD", ".*",
"^[\\s,]+" + # ws/comma prefix
"|[\\s,]*,\\s*(?:\0)\\b" + # ,<remove>
"|[\\s,]*(,\\s*[^\\s,]+)" + # ,<keep>
"|(?:\0)(?:[\\s,]+|$)" + # <remove>,
"|([^\\s,]+)" + # <keep>
"|[\\s,]+$"),
case_sensitive=false);
std.log(
regsub(
"A|AB|ABD", ".*",
"^[\\s,]+" + # ws/comma prefix
"|[\\s,]*,\\s*(?:\0)\\b" + # ,<remove>
"|[\\s,]*(,\\s*[^\\s,]+)" + # ,<keep>
"|(?:\0)([\\s,]*|$)" + # <remove>,
"|([^\\s,]+)" + # <keep>
"|[\\s,]+$"));
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
if (blacklist.match(req.http.in)) {
set resp.http.out = blacklist.suball(req.http.in, "\1\2");
if (resp.http.out == "") {
unset resp.http.out;
}
} else {
set resp.status = 204;
}
return (deliver);
}
} -start
client c1 {
txreq -hdr "in: , ,, , A, ABD,, , AB ,, ,"
rxresp
expect resp.status == 200
expect resp.http.out == <undef>
txreq -hdr "in: X, ABC,Z"
rxresp
# expect resp.status == 204
# expect resp.http.out == <undef>
expect resp.status == 200
expect resp.http.out == "X, ABC,Z"
# -
txreq -hdr "in: X, AB"
rxresp
expect resp.status == 200
expect resp.http.out == "X"
txreq -hdr "in: , ,, X, AB"
rxresp
expect resp.status == 200
expect resp.http.out == "X"
txreq -hdr "in: X, AB, ,, "
rxresp
expect resp.status == 200
expect resp.http.out == "X"
# -
txreq -hdr "in: AB,X"
rxresp
expect resp.status == 200
expect resp.http.out == "X"
txreq -hdr "in: , ,, AB,X"
rxresp
expect resp.status == 200
expect resp.http.out == "X"
txreq -hdr "in: AB,X, ,, "
rxresp
expect resp.status == 200
expect resp.http.out == "X"
txreq -hdr "in: ABD,X, ,, "
rxresp
expect resp.status == 200
expect resp.http.out == "X"
# -
txreq -hdr "in: X, AB, Y"
rxresp
expect resp.status == 200
expect resp.http.out == "X, Y"
txreq -hdr "in: , ,, X, AB, Y"
rxresp
expect resp.status == 200
expect resp.http.out == "X, Y"
txreq -hdr "in: X, AB, ,,Y "
rxresp
expect resp.status == 200
expect resp.http.out == "X,Y"
# XXX FAILS
# txreq -hdr "in: X, AB-C, ,,Y "
# rxresp
#
# expect resp.status == 200
# expect resp.http.out == "X, AB-C, Y"
} -run
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