aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-08 20:37:21 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-08 20:37:21 +0900
commit70418e74c948917d4f6b3f03896abae01c44256a (patch)
tree60dfa8cd03695b5a72717c1dbefd49d71ec42d9d /lib/plum
parentee159b255fbf77c04d8a68ec573d195e6fbe0791 (diff)
downloadplum-70418e74c948917d4f6b3f03896abae01c44256a.tar.gz
client: add :http2 option
Diffstat (limited to 'lib/plum')
-rw-r--r--lib/plum/client.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/plum/client.rb b/lib/plum/client.rb
index cd1315b..a4fe243 100644
--- a/lib/plum/client.rb
+++ b/lib/plum/client.rb
@@ -9,6 +9,7 @@ module Plum
hostname: nil,
http2_settings: {},
user_agent: "plum/#{Plum::VERSION}",
+ http2: true,
}.freeze
attr_reader :host, :port, :config
@@ -146,7 +147,7 @@ module Plum
def _start
@started = true
- http2 = true
+ http2 = @config[:http2]
unless @socket
@socket = TCPSocket.open(host, port)
if config[:tls]
@@ -159,7 +160,7 @@ module Plum
if @socket.respond_to?(:alpn_protocol)
http2 = @socket.alpn_protocol == "h2"
- elsif sock.respond_to?(:npn_protocol)
+ elsif @socket.respond_to?(:npn_protocol) # TODO: remove
http2 = @socket.npn_protocol == "h2"
else
http2 = false
@@ -178,17 +179,19 @@ module Plum
ctx = OpenSSL::SSL::SSLContext.new
ctx.ssl_version = :TLSv1_2
ctx.verify_mode = @config[:verify_mode]
- ctx.ciphers = "ALL:!" + HTTPSServerConnection::CIPHER_BLACKLIST.join(":!")
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths
ctx.cert_store = cert_store
- if ctx.respond_to?(:alpn_protocols)
- ctx.alpn_protocols = ["h2", "http/1.1"]
- end
- if ctx.respond_to?(:npn_select_cb) # TODO: RFC 7540 does not define protocol negotiation with NPN
- ctx.npn_select_cb = -> protocols {
- protocols.include?("h2") ? "h2" : protocols.first
- }
+ if @config[:http2]
+ ctx.ciphers = "ALL:!" + HTTPSServerConnection::CIPHER_BLACKLIST.join(":!")
+ if ctx.respond_to?(:alpn_protocols)
+ ctx.alpn_protocols = ["h2", "http/1.1"]
+ end
+ if ctx.respond_to?(:npn_select_cb) # TODO: RFC 7540 does not define protocol negotiation with NPN
+ ctx.npn_select_cb = -> protocols {
+ protocols.include?("h2") ? "h2" : protocols.first
+ }
+ end
end
ctx
end