lib/httpx/channel/http2.rb in httpx-0.1.0 vs lib/httpx/channel/http2.rb in httpx-0.2.0
- old
+ new
@@ -5,10 +5,16 @@
module HTTPX
class Channel::HTTP2
include Callbacks
include Loggable
+ Error = Class.new(Error) do
+ def initialize(id, code)
+ super("stream #{id} closed with error: #{code}")
+ end
+ end
+
attr_reader :streams, :pending
def initialize(buffer, options)
@options = Options.new(options)
@max_concurrent_requests = @options.max_concurrent_requests
@@ -155,14 +161,22 @@
end
def on_stream_close(stream, request, error)
return handle(request, stream) if request.expects?
if error
- emit(:error, request, error)
+ ex = Error.new(stream.id, error)
+ ex.set_backtrace(caller)
+ emit(:error, request, ex)
else
response = request.response
- emit(:response, request, response)
+ if response.status == 421
+ ex = MisdirectedRequestError.new(response)
+ ex.set_backtrace(caller)
+ emit(:error, request, ex)
+ else
+ emit(:response, request, response)
+ end
end
log(level: 2, label: "#{stream.id}: ") { "closing stream" }
@streams.delete(request)
send(@pending.shift) unless @pending.empty?
@@ -175,10 +189,15 @@
def on_settings(*)
@max_concurrent_requests = [@max_concurrent_requests,
@connection.remote_settings[:settings_max_concurrent_streams]].min
end
- def on_close(*)
+ def on_close(_last_frame, error, _payload)
+ if error
+ ex = Error.new(0, error)
+ ex.set_backtrace(caller)
+ emit(:error, request, ex)
+ end
return unless @connection.state == :closed && @connection.active_stream_count.zero?
emit(:close)
end
def on_frame_sent(frame)