Extract proxy/config common functions for reuse

Refactor proxy to use the common config.  This is a prereq for #356 and the commits 
have had feedback from @thockin only.
Also fix tests.
The locks here are close enough that I'd argue that defer doesn't significantly improve readability (in the absence of an if).  Will bow to strong opinions though :)