lib/httpx/plugins/proxy/http.rb in httpx-0.0.2 vs lib/httpx/plugins/proxy/http.rb in httpx-0.0.3
- old
+ new
@@ -20,26 +20,27 @@
if @parameters.authenticated?
connect_request.headers["proxy-authentication"] = "Basic #{@parameters.token_authentication}"
end
parser.send(connect_request)
else
- transition(:open)
+ transition(:connected)
end
end
def transition(nextstate)
case nextstate
when :connecting
return unless @state == :idle
@io.connect
- return if @io.closed?
+ return unless @io.connected?
@parser = ConnectProxyParser.new(@write_buffer, @options.merge(max_concurrent_requests: 1))
@parser.once(:response, &method(:on_connect))
@parser.on(:close) { transition(:closing) }
proxy_connect
- return if @state == :open
- when :open
+ return if @state == :connected
+ when :connected
+ return unless @state == :idle || @state == :connecting
case @state
when :connecting
@parser.close
@parser = nil
when :idle
@@ -54,10 +55,10 @@
def on_connect(_request, response)
if response.status == 200
req, _ = @pending.first
request_uri = req.uri
@io = ProxySSL.new(@io, request_uri, @options)
- transition(:open)
+ transition(:connected)
throw(:called)
else
pending = @pending.map(&:first) + @parser.pending
while (req = pending.shift)
emit(:response, req, response)