refactor ProxyHandler, remove duplicate code
add comments
Merge pull request #189 from mitmproxy/refactor_proxyhandler

Refactor ProxyHandler