add support for request cache-control headers

And a few minor cleanups and bugfixes.