lib/httpx/connection/http1.rb in httpx-0.23.4 vs lib/httpx/connection/http1.rb in httpx-0.24.0

- old
+ new

@@ -131,46 +131,59 @@ log(color: :yellow) { h.each.map { |f, v| "-> HEADER: #{f}: #{v.join(", ")}" }.join("\n") } response.merge_headers(h) end def on_data(chunk) - return unless @request + request = @request + return unless request + log(color: :green) { "-> DATA: #{chunk.bytesize} bytes..." } log(level: 2, color: :green) { "-> #{chunk.inspect}" } - response = @request.response + response = request.response response << chunk + rescue StandardError => e + error_response = ErrorResponse.new(request, e, request.options) + request.response = error_response + dispatch end def on_complete - return unless @request + request = @request + return unless request + log(level: 2) { "parsing complete" } dispatch end def dispatch - if @request.expects? + request = @request + + if request.expects? @parser.reset! - return handle(@request) + return handle(request) end - request = @request @request = nil @requests.shift response = request.response - response.finish! + response.finish! unless response.is_a?(ErrorResponse) emit(:response, request, response) if @parser.upgrade? response << @parser.upgrade_data throw(:called) end @parser.reset! @max_requests -= 1 - manage_connection(response) + if response.is_a?(ErrorResponse) + disable + else + manage_connection(response) + end send(@pending.shift) unless @pending.empty? end def handle_error(ex)