use code from @yudai to support http/https proxy