lib/httpx/plugins/h2c.rb in httpx-1.1.5 vs lib/httpx/plugins/h2c.rb in httpx-1.2.0

- old
+ new

@@ -2,13 +2,13 @@ module HTTPX module Plugins # # This plugin adds support for upgrading a plaintext HTTP/1.1 connection to HTTP/2 - # (https://tools.ietf.org/html/rfc7540#section-3.2) + # (https://datatracker.ietf.org/doc/html/rfc7540#section-3.2) # - # https://gitlab.com/os85/httpx/wikis/Upgrade#h2c + # https://gitlab.com/os85/httpx/wikis/Connection-Upgrade#h2c # module H2C VALID_H2C_VERBS = %w[GET OPTIONS HEAD].freeze class << self @@ -71,23 +71,35 @@ if prev_parser prev_parser.reset @inflight -= prev_parser.requests.size end - parser_options = @options.merge(max_concurrent_requests: request.options.max_concurrent_requests) - @parser = H2CParser.new(@write_buffer, parser_options) + @parser = H2CParser.new(@write_buffer, @options) set_parser_callbacks(@parser) @inflight += 1 @parser.upgrade(request, response) @upgrade_protocol = "h2c" - if request.options.max_concurrent_requests != @options.max_concurrent_requests - @options = @options.merge(max_concurrent_requests: nil) - end - prev_parser.requests.each do |req| req.transition(:idle) send(req) + end + end + + private + + def send_request_to_parser(request) + super + + return unless request.headers["upgrade"] == "h2c" && parser.is_a?(Connection::HTTP1) + + max_concurrent_requests = parser.max_concurrent_requests + + return if max_concurrent_requests == 1 + + parser.max_concurrent_requests = 1 + request.once(:response) do + parser.max_concurrent_requests = max_concurrent_requests end end end end register_plugin(:h2c, H2C)