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.
I like to write an accessor function to do things like this, specifically so that it can use defer. But I don't have a strong opinion.