diff --git a/lib/httpx/channel.rb b/lib/httpx/channel.rb index 4459675a..5f1008ef 100644 --- a/lib/httpx/channel.rb +++ b/lib/httpx/channel.rb @@ -115,6 +115,11 @@ module HTTPX nil end + def upgrade_parser(protocol) + @parser.close if @parser + @parser = build_parser(protocol) + end + private def connect @@ -151,12 +156,14 @@ module HTTPX end def parser - @parser || begin - @parser = registry(@io.protocol).new(@write_buffer, @options) - @parser.on(:response, &@on_response) - @parser.on(:close) { throw(:close, self) } - @parser - end + @parser ||= build_parser + end + + def build_parser(protocol=@io.protocol) + parser = registry(protocol).new(@write_buffer, @options) + parser.on(:response, &@on_response) + parser.on(:close) { throw(:close, self) } + parser end end end diff --git a/lib/httpx/channel/http2.rb b/lib/httpx/channel/http2.rb index c36b62cd..e60f00e5 100644 --- a/lib/httpx/channel/http2.rb +++ b/lib/httpx/channel/http2.rb @@ -202,6 +202,14 @@ module HTTPX stream.refuse # TODO: policy for handling promises end + + def method_missing(meth, *args, &blk) + if @connection.respond_to?(meth) + @connection.__send__(meth, *args, &blk) + else + super + end + end end Channel.register "h2", Channel::HTTP2 end diff --git a/lib/httpx/options.rb b/lib/httpx/options.rb index 178c1cbe..6bc0b562 100644 --- a/lib/httpx/options.rb +++ b/lib/httpx/options.rb @@ -42,6 +42,7 @@ module HTTPX :debug => ENV.key?("HTTPX_DEBUG") ? $stderr : nil, :debug_level => (ENV["HTTPX_DEBUG"] || 1).to_i, :ssl => { alpn_protocols: %w[h2 http/1.1] }, + :http2_settings => { settings_enable_push: 0 }, :fallback_protocol => "http/1.1", :timeout => Timeout.by(:per_operation), :headers => {}, @@ -84,7 +85,7 @@ module HTTPX %w[ params form json body - follow ssl max_retries + follow ssl http2_settings max_retries request_class response_class headers_class response_body_class io fallback_protocol debug debug_level ].each do |method_name| @@ -97,9 +98,7 @@ module HTTPX merged = h1.merge(h2) do |k, v1, v2| case k - when :headers - v1.merge(v2) - when :ssl + when :headers, :ssl, :http2_settings v1.merge(v2) else v2