Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions bin/varnishncsa/varnishncsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ addf_vsl(enum VSL_tag_e tag, long i, const char *prefix)
assert(i <= INT_MAX);
w->idx = i;
if (prefix != NULL) {
w->prefixlen = asprintf(&w->prefix, "%s:", prefix);
w->prefixlen = asprintf(&w->prefix, "%s", prefix);
assert(w->prefixlen > 0);
}
VTAILQ_INSERT_TAIL(&CTX.watch_vsl, w, list);
Expand Down Expand Up @@ -895,12 +895,17 @@ parse_format(const char *format)

static int
isprefix(const char *prefix, size_t len, const char *b,
const char *e, const char **next)
const char *e, const char **next, const char *sep)
{
assert(len > 0);
if (e < b + len || strncasecmp(b, prefix, len))
return (0);
b += len;
if (b < e && sep != NULL && strchr(sep, *b) == NULL)
return (0);
if (b < e && sep != NULL)
b++;

if (next) {
while (b < e && *b == ' ')
b++;
Expand Down Expand Up @@ -987,7 +992,7 @@ process_hdr(enum format_policy fp, const struct watch_head *head, const char *b,

VTAILQ_FOREACH(w, head, list) {
CHECK_OBJ_NOTNULL(w, WATCH_MAGIC);
if (!isprefix(w->key, w->keylen, b, e, &p))
if (!isprefix(w->key, w->keylen, b, e, &p, NULL))
continue;

if (w->match) {
Expand Down Expand Up @@ -1017,7 +1022,7 @@ process_vsl(const struct vsl_watch_head *head, enum VSL_tag_e tag,
continue;
p = b;
if (w->prefixlen > 0 &&
!isprefix(w->prefix, w->prefixlen, b, e, &p))
!isprefix(w->prefix, w->prefixlen, b, e, &p, ": "))
continue;
if (w->idx == 0)
frag_line(FMTPOL_INTERNAL, p, e, &w->frag);
Expand Down Expand Up @@ -1116,7 +1121,7 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
0, NULL);
break;
case SLT_Timestamp:
#define ISPREFIX(a, b, c, d) isprefix(a, strlen(a), b, c, d)
#define ISPREFIX(a, b, c, d) isprefix(a, strlen(a), b, c, d, NULL)
if (ISPREFIX("Start:", b, e, &p)) {
frag_fields(FMTPOL_INTERNAL, p, e, 1,
&CTX.frag[F_tstart], 0, NULL);
Expand Down
15 changes: 15 additions & 0 deletions bin/varnishtest/tests/u00003.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ varnish v1 -vcl+backend {
sub vcl_hit {
return (synth(404));
}

sub vcl_backend_response {
set beresp.ttl = 360s;
}
} -start

shell {
Expand Down Expand Up @@ -197,3 +201,14 @@ shell {
}

# ESI coverage in e00003.vtc

# %{VSL:tag:prefix} with space separator

shell {
varnishncsa -n ${v1_name} -d -b -F '%{VSL:Begin:bereq[2]}x %{VSL:TTL:RFC[1]}x %{VSL:TTL:VCL[1]}x %{VSL:BerespHeader:server}x' -k1 > vsl_prefix.txt

cat >expected_vsl_prefix.txt <<-EOF
fetch 120 360 s1
EOF
diff -u expected_vsl_prefix.txt vsl_prefix.txt
}
2 changes: 1 addition & 1 deletion doc/sphinx/reference/varnishncsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Supported formatters are:

The record prefix will limit the matches to those records that
have this prefix as the first part of the record content followed
by a colon.
by a colon or a white space.

The field will, if present, treat the log record as a white
space separated list of fields, and only the nth part of the
Expand Down