aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-05-08 01:10:22 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-05-08 15:17:15 +0900
commit2e0428a50a1190a06fded9dc52fce70c6e59e8a4 (patch)
tree60e587d9594b924d88b2bb6bffc902076986775e
parent9f0fbeb833bb8929946abe34a751e21a7ead9886 (diff)
downloadplum-2e0428a50a1190a06fded9dc52fce70c6e59e8a4.tar.gz
client: replace 'scheme' option with 'https' option
The scheme is always 'http' or 'https', so boolean is sufficient.
-rw-r--r--lib/plum/client.rb8
-rw-r--r--lib/plum/client/client_session.rb2
-rw-r--r--test/plum/client/test_client.rb4
3 files changed, 7 insertions, 7 deletions
diff --git a/lib/plum/client.rb b/lib/plum/client.rb
index fbddd63..bf288c9 100644
--- a/lib/plum/client.rb
+++ b/lib/plum/client.rb
@@ -2,7 +2,7 @@
module Plum
class Client
DEFAULT_CONFIG = {
- scheme: "https",
+ https: true,
hostname: nil,
verify_mode: OpenSSL::SSL::VERIFY_PEER,
ssl_context: nil,
@@ -31,7 +31,7 @@ module Plum
else
@socket = nil
@host = host
- @port = port || (config[:scheme] == "https" ? 443 : 80)
+ @port = port || (config[:https] ? 443 : 80)
end
@config = DEFAULT_CONFIG.merge(hostname: host).merge(config)
@started = false
@@ -135,7 +135,7 @@ module Plum
def _connect
@socket = TCPSocket.open(@host, @port)
- if @config[:scheme] == "https"
+ if @config[:https]
ctx = @config[:ssl_context] || new_ssl_ctx
@socket = OpenSSL::SSL::SSLSocket.new(@socket, ctx)
@socket.hostname = @config[:hostname] if @socket.respond_to?(:hostname=)
@@ -151,7 +151,7 @@ module Plum
@started = true
nego = @socket || _connect
- if @config[:scheme] == "https"
+ if @config[:https]
klass = nego ? ClientSession : LegacyClientSession
else
klass = UpgradeClientSession
diff --git a/lib/plum/client/client_session.rb b/lib/plum/client/client_session.rb
index 09539aa..cdc3e7b 100644
--- a/lib/plum/client/client_session.rb
+++ b/lib/plum/client/client_session.rb
@@ -39,7 +39,7 @@ module Plum
headers = { ":method" => nil,
":path" => nil,
":authority" => @config[:hostname],
- ":scheme" => @config[:scheme]
+ ":scheme" => @config[:https] ? "https" : "http",
}.merge(headers)
response = Response.new(**options)
diff --git a/test/plum/client/test_client.rb b/test/plum/client/test_client.rb
index 29f5b2d..13aa82a 100644
--- a/test/plum/client/test_client.rb
+++ b/test/plum/client/test_client.rb
@@ -82,13 +82,13 @@ class ClientTest < Minitest::Test
def test_session_socket_http2_https
sock = StringSocket.new
- client = Client.start(sock, nil, scheme: "https")
+ client = Client.start(sock, nil, https: true)
assert(client.session.class == ClientSession)
end
def test_session_socket_http2_http
sock = StringSocket.new("HTTP/1.1 100\r\n\r\n")
- client = Client.start(sock, nil, scheme: "http")
+ client = Client.start(sock, nil, https: false)
assert(client.session.class == UpgradeClientSession)
end