passing fallback protocol as option; this will allow to override, specially in the case when user knows that server can do unencrypted http/2

This commit is contained in:
HoneyryderChuck 2017-12-11 22:28:12 +00:00
parent 4e094f79d0
commit e6a5fbdf45
3 changed files with 5 additions and 2 deletions

View File

@ -10,6 +10,7 @@ module HTTPX
attr_reader :ip, :port, :uri
def initialize(uri, options)
@fallback_protocol = options.fallback_protocol
@connected = false
@uri = uri
@ip = TCPSocket.getaddress(@uri.host)
@ -32,7 +33,7 @@ module HTTPX
end
def protocol
"http/1.1"
@fallback_protocol
end
def connect

View File

@ -43,6 +43,7 @@ module HTTPX
defaults = {
:proxy => {},
:ssl => { alpn_protocols: %w[h2 http/1.1] },
:fallback_protocol => "http/1.1",
:timeout => Timeout.by(:per_operation),
:headers => {},
:cookies => {},
@ -94,7 +95,7 @@ module HTTPX
params form json body
proxy follow ssl max_retries
request_class response_class headers_class response_body_class
io
io fallback_protocol
].each do |method_name|
def_option(method_name)
end

View File

@ -67,6 +67,7 @@ class OptionsSpec < Minitest::Test
:form => {:bar => "bar"},
:timeout => Timeout::PerOperation.new,
:ssl => {:foo => "bar", :alpn_protocols => %w[h2 http/1.1] },
:fallback_protocol => "http/1.1",
:headers => {"Foo" => "foo", "Accept" => "xml", "Bar" => "bar"},
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080},
:cookies => {},