proposal part 1 - VCL: edit header tokens/entities

Nils Goroll slink at
Mon Sep 1 19:01:44 CEST 2014

On 28/08/14 08:57, Poul-Henning Kamp wrote:
> Btw, mildly related to this:  Long time ago we talked about being able
> to work on sub-parts of http headers:
> 	if (INT(beresp.http.cache-control.max-age, 0) > 1200) {
> 		set beresp.http.cache-contro.max-age = 1200;
> 	}
> We may want to reconsider this before we write too intricate VCL

phk had asked me to come up with a sketch of which VRT functions we'd need for
this, but I'd rather get some input about several ways to define the VCL first.

The general idea is that, while whole headers can be accessed using

	[un]set where.http.headername

tokens/entities in headers could be accessed using

	[un]set where.http.headername.token
	[un]set where.http.headername.token.option

VCL/VCC would know that for most headers elements are split by comma (,) and
key/value pairs are split by equals (=) and it would be aware of exceptions for
other well known headers (for instance the Cookie request header, if we take it
into scope).

The first issue here is how we denote token and option in VCL.

According to we cannot assume
some "special" character not to be contained in a header token/entity name or value.

One suggestion we have discussed on irc was to use the array notation, but this
would make it necessary to quote [ and ], so

	set beresp.http.Foo.[g\[oo\]g\\l"e] = "watching";

would yield

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

if there was no Foo header (and add it otherwise).

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.

Some more examples (hopefully slightly more realistic) using this notation with
before and after

example #1

		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, */*

	set req.http.Accept.{""quoted"/printable"};

		-> Accept: text/plain; q=3.14, text/x-dvi, */*, "quoted"/printable

	unset req.http.Accept."*/*";

		-> Accept: text/plain; q=3.14, text/x-dvi, "quoted"/printable

example #2

		Vary: Accept-Language

	set beresp.http.Vary."Accept-Encoding";

		-> Vary: Accept-Language, Accept-Encoding

	unset beresp.http.Vary."Accept-Language";

		-> Vary: Accept-Encoding

	unset beresp.http.Vary."Accept-Encoding";

		-> (void) - header removed

Feedback welcome.

More information about the varnish-dev mailing list