Would appreciate reciews of a header element parsing/modification prototype

Nils Goroll slink at schokola.de
Sun Sep 28 19:43:30 CEST 2014


Hi,

On 22/09/14 09:37, Poul-Henning Kamp wrote:
> 
> I would do it something like this instead:
> 
> 	did = 0
> 	Reserve workspace
> 	loop over tokens in src-header
> 		if token != target
> 			copy token to workspace
> 			did = 1
> 	if (did):
> 		release unused workspace
> 	else:
> 		return all reserved workspace
> 	return (did)
> 
> That would largely be a duplication of http_GetHdrToken() just a few
> lines longer.

I actually have done an implementation along these lines, but I did not like it
at all, it got really lengthy, lacked generality etc etc.


With the idea in mind that we could have general header element editing
facilities (no matter in a vmod or core/vcl), I have written a more generic
prototype around the suggested http_RemoveHdrToken function following the design
example of struct http and the HTTP_* functions.

For the protoype I have worked in cache_http.c, the source structure and the
question of which functions to declare static are things I'd like to think about
later.

struct httphdr holds two txt arrays for the parse of a header line - one for
names and one for values (think "max-age=200")

HTTPHDR_estimate and HTTPHDR_create closely follow the HTTP_ examples.

HTTPHDR_Tokenize dissects a header line into element keys and values. The
seperating characters are to be generalized later.

HTTPHDR_Join constructs a header line from a struct httphdr on some buffer provided.

HTTPHDR_SameToken compares two header elemnts passed as (c)txt structs either
case sensitively for the quoted or case insensitively for the unquoted case.

HTTPHDR_RemoveToken nulls all instances of a token name in a struct httphdr

http_RemoveHdrToken (and the corresponding VRT) is the PoC implementation. It
builds the struct httphdr parse on the stack and only leaves a finalized header
on the workspace.

bin/varnishtest/tests/removehdrtoken.vtc is a working test for the remove header
token example.


I'd very much appreciate feedback on this.

Nils
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-prototype-header-element-parsing.patch
Type: text/x-patch
Size: 14712 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20140928/c130549d/attachment.bin>


More information about the varnish-dev mailing list