def unbind
if (@state == :finished) && (@last_effective_url != @uri) && (@redirects < @options[:redirects])
begin
@uri = @last_effective_url
@redirects += 1
req = HttpOptions.new(@method, @uri, @options)
reconnect(req.host, req.port)
@response_header = HttpResponseHeader.new
@state = :response_header
@response = ''
@data.clear
rescue EventMachine::ConnectionError => e
on_error(e.message, true)
end
else
if @state == :finished || (@state == :body && @bytes_remaining.nil?)
succeed(self)
else
@disconnect.call(self) if @state == :websocket and @disconnect
fail(self)
end
end
end