File tree Expand file tree Collapse file tree 1 file changed +11
-14
lines changed Expand file tree Collapse file tree 1 file changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -146,18 +146,17 @@ def with_net_http_connection(env)
146146 end
147147
148148 def net_http_connection ( env )
149- proxy = env [ :request ] [ :proxy ]
150- klass = if proxy . nil?
151- Net ::HTTP
152- elsif proxy . uri . scheme != 'socks'
153- http_proxy ( proxy )
154- else
155- socks_proxy ( proxy )
156- end
149+ klass = proxy_class ( env [ :request ] [ :proxy ] )
157150 port = env [ :url ] . port || ( env [ :url ] . scheme == 'https' ? 443 : 80 )
158151 klass . new ( env [ :url ] . hostname , port )
159152 end
160153
154+ def proxy_class ( proxy )
155+ return Net ::HTTP if proxy . nil?
156+ return http_proxy ( proxy ) unless proxy . uri . scheme != 'socks'
157+ socks_proxy ( proxy )
158+ end
159+
161160 def http_proxy ( proxy )
162161 Net ::HTTP ::Proxy (
163162 proxy [ :uri ] . host ,
@@ -168,14 +167,12 @@ def http_proxy(proxy)
168167 end
169168
170169 def socks_proxy ( proxy )
171- TCPSocket . socks_username = proxy [ :user ] if proxy [ :user ]
172- TCPSocket . socks_password = proxy [ :password ] if proxy [ :password ]
173- Net ::HTTP ::SOCKSProxy ( proxy [ :uri ] . host , proxy [ :uri ] . port )
174- rescue NoMethodError => err
175- if err . to_s =~ /socks/i
170+ if !Net ::HTTP . respond_to? ( :SOCKSProxy )
176171 raise "SOCKS proxy support requires the socksify gem ~> 1.7.1"
177172 end
178- raise
173+
174+ Net ::HTTP ::SOCKSProxy ( proxy [ :uri ] . host , proxy [ :uri ] . port ,
175+ proxy [ :user ] , proxy [ :password ] )
179176 end
180177
181178 def configure_ssl ( http , ssl )
You can’t perform that action at this time.
0 commit comments