proposal part 1 - VCL: edit header tokens/entities

Geoff Simmons geoff at
Tue Sep 2 08:33:51 CEST 2014

Hash: SHA256

On 9/1/14 7:01 PM, Nils Goroll wrote:
> According to we
> cannot assume some "special" character not to be contained in a
> header token/entity name or value.

Maybe so, but in practice this sort of example is extremely unusual;
it would be OK if the syntax necessary for it is cumbersome.

> Foo: g[oo]g\l"e=watching

> The best suggestion for a syntax I could think of so far is to use
> the existing string notation, so
> set beresp.http.Foo.{"g[oo]g\l"e"} = "watching";
> would yield the same result.

It looks like this would work technically, but consider that VCL
strives for syntax that is familiar from other familiar languages. I
personally have never seen anything like that; "that looks weird"
might be a common user feedback.

Suggestion: stay with the quoted strings, but enclose them in square
brackets rather than use the dot notation. Then it looks the syntax
for associative arrays used by shells, Perl, Ruby, PHP and so forth.

set req.http.Accept["q"] = 3.14;
unset req.http.Accept["*/*"];
if (beresp.http.Surrogate-Control["max-age"] ~ "\d+")
if (beresp.http.Surrogate-Control["max-age"]) // boolean context

It gets a little repetitive with brackets when the string includes
quotation marks, then we'd have something like [{"..."}], but I think
that's OK.

I'm not a big fan of:

> Accept: text/plain; q=0.5, text/x-dvi, */*
> set req.http.Accept."text/plain"."q" = 3.14;
> -> Accept: text/plain; q=3.14, text/x-dvi, */*

I had to look at that several times to realize what's going on -- the
operation adds 'text/plain; q=3.14' to a comma-separated list. At
first glance it looked like the set operation was doing two things at
once, adding both 'text/plain', which is not set to anything, and 'q',
which is set to the right-hand side.

You'd think it should actually be (my notation suggestion this time):

set req.http.Accept["text/plain; q"] = 3.14:

Or of:

> set req.http.Accept.{""quoted"/printable"};
> -> Accept: text/plain; q=3.14, text/x-dvi, */*, "quoted"/printable
> Vary: Accept-Language
> set beresp.http.Vary."Accept-Encoding";
> -> Vary: Accept-Language, Accept-Encoding

I think we should have different operations, other than set and unset,
for comma-separated lists of scalar values that aren't of the form
x=y. Something like add and remove for lists. The VMOD header actually
comes very close to providing something like that (but not quite).

'set LHS;' without a RHS looks like one of those gotcha tests for C
programmers ("what does 'x;' do? did you know that it's even possible?").

These admittedly do look intuitive.

> -> Vary: Accept-Language, Accept-Encoding
> unset beresp.http.Vary."Accept-Language";
> -> Vary: Accept-Encoding
> unset beresp.http.Vary."Accept-Encoding";
> -> (void) - header removed

- -- 
UPLEX Systemoptimierung
Scheffelstraße 32
22301 Hamburg
Mob: +49-176-63690917
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)


More information about the varnish-dev mailing list