Inspect Request bodies?

Tim Kientzle tim at metaweb.com
Wed Nov 5 20:29:11 CET 2008


Under certain circumstances, I want to inspect the body of a
POST request at the proxy cache.

It don't see any hooks for this in the current Varnish 2.0.1,
but I've skimmed the source and it looks feasible:

  * I'll need code to actually read and store the POST body in memory
    (including updates to the PASS handler and other places to
    use the in-memory data when it's available)

  * I'll need to add VCL functions to actually analyze the POST body.

The second part looks pretty straightforward.  The VCL engine
seems quite modular and extensible.  Because VCL routines run in
per-request threads, it should be feasible to do more time-consuming
operations using straightforward sequential code.  (I've also looked
at extending Squid or Nginx, but breaking down some of these operations
into the necessary state machines would be rather tedious.)

The first part looks trickier.  Has anyone here tried anything
similar?  Any pointers (particular source files I should pay attention
to or memory-management issues I should keep in mind)?

Finally, has anyone else encountered similar requirements that
might benefit from this?  (I.e., if I do get this to work, is
it worth cleaning up the code to contribute back?)

Of course, if Varnish already provides some of this and I've
simply missed it, then that's even better. ;-)

Cheers,

Tim

P.S.  For the curious, there are two specific issues I'm
exploring:  First, I have an API which prefers GET but supports
POST if the arguments are too long; I'd like to accurately
cache responses to these larger requests.  Second, I've been
exploring request-signing techniques borrowed from OAuth.  Both
of these boil down to computing a hash over all query arguments,
including those in the POST body.  So far, I've been handling
these issues at the app server, but I've got a growing suite
of applications running in that layer and I'd like to move the
redundant code into a common proxy layer, so I've been surveying
existing proxy implementations to see which ones are most amenable
to this kind of extension.




More information about the varnish-misc mailing list