lib/httpx/connection/http2.rb in httpx-0.10.0 vs lib/httpx/connection/http2.rb in httpx-0.10.1
- old
+ new
@@ -49,16 +49,12 @@
return :r if @buffer.empty?
:rw
end
- def reset
- init_connection
- end
-
- def close(*args)
- @connection.goaway(*args) unless @connection.state == :closed
+ def close
+ @connection.goaway unless @connection.state == :closed
emit(:close)
end
def empty?
@connection.state == :closed || @streams.empty?
@@ -161,10 +157,13 @@
# initiate it.
#
@connection.send_connection_preface
end
+ alias_method :reset, :init_connection
+ public :reset
+
def handle_stream(stream, request)
stream.on(:close, &method(:on_stream_close).curry[stream, request])
stream.on(:half_close) do
log(level: 2) { "#{stream.id}: waiting for response..." }
end
@@ -268,20 +267,20 @@
@max_concurrent_requests = [@max_concurrent_requests, @max_requests].min
send_pending
end
def on_close(_last_frame, error, _payload)
+ is_connection_closed = @connection.state == :closed
if error && error != :no_error
+ @buffer.clear if is_connection_closed
ex = Error.new(0, error)
ex.set_backtrace(caller)
- @streams.each_key do |request|
- emit(:error, request, ex)
- end
+ handle_error(ex)
end
- return unless @connection.state == :closed && @streams.size.zero?
+ return unless is_connection_closed && @streams.size.zero?
- emit(:close)
+ emit(:close, is_connection_closed)
end
def on_frame_sent(frame)
log(level: 2) { "#{frame[:stream]}: frame was sent!" }
log(level: 2, color: :blue) do
@@ -315,10 +314,10 @@
def on_origin(origin)
emit(:origin, origin)
end
def on_pong(ping)
- if !@pings.delete(ping)
+ if !@pings.delete(ping.to_s)
close(:protocol_error, "ping payload did not match")
else
emit(:pong)
end
end