lib/httpx/plugins/h2c.rb in httpx-0.22.5 vs lib/httpx/plugins/h2c.rb in httpx-0.23.0
- old
+ new
@@ -7,28 +7,24 @@
# (https://tools.ietf.org/html/rfc7540#section-3.2)
#
# https://gitlab.com/os85/httpx/wikis/Upgrade#h2c
#
module H2C
- VALID_H2C_VERBS = %i[get options head].freeze
+ VALID_H2C_VERBS = %w[GET OPTIONS HEAD].freeze
class << self
- def load_dependencies(*)
+ def load_dependencies(klass)
require "base64"
- end
-
- def configure(klass)
klass.plugin(:upgrade)
- klass.default_options.upgrade_handlers.register "h2c", self
end
def call(connection, request, response)
connection.upgrade_to_h2c(request, response)
end
def extra_options(options)
- options.merge(max_concurrent_requests: 1)
+ options.merge(max_concurrent_requests: 1, upgrade_handlers: options.upgrade_handlers.merge("h2c" => self))
end
end
module InstanceMethods
def send_requests(*requests)
@@ -36,11 +32,11 @@
return super unless VALID_H2C_VERBS.include?(upgrade_request.verb) && upgrade_request.scheme == "http"
connection = pool.find_connection(upgrade_request.uri, upgrade_request.options)
- return super if connection && connection.upgrade_protocol == :h2c
+ return super if connection && connection.upgrade_protocol == "h2c"
# build upgrade request
upgrade_request.headers.add("connection", "upgrade")
upgrade_request.headers.add("connection", "http2-settings")
upgrade_request.headers["upgrade"] = "h2c"
@@ -81,10 +77,10 @@
parser_options = @options.merge(max_concurrent_requests: request.options.max_concurrent_requests)
@parser = H2CParser.new(@write_buffer, parser_options)
set_parser_callbacks(@parser)
@inflight += 1
@parser.upgrade(request, response)
- @upgrade_protocol = :h2c
+ @upgrade_protocol = "h2c"
if request.options.max_concurrent_requests != @options.max_concurrent_requests
@options = @options.merge(max_concurrent_requests: nil)
end