From 5b21ac149fe522f478ab6e55aef0ef0119ea28df Mon Sep 17 00:00:00 2001 From: lkitching Date: Tue, 1 Aug 2017 12:22:11 +0100 Subject: [PATCH] Use query endpoint URI scheme to configure SSL. Issue #64 - Use SSL for SPARQL queries where the scheme of the query endpoint URI is https rather than expecting the default SSL port of 443. --- lib/tripod/streaming.rb | 2 +- spec/tripod/streaming_spec.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tripod/streaming.rb b/lib/tripod/streaming.rb index 4c984f6..209b63c 100644 --- a/lib/tripod/streaming.rb +++ b/lib/tripod/streaming.rb @@ -6,7 +6,7 @@ module Streaming def self.create_http_client(uri, opts) client = Net::HTTP.new(uri.host, uri.port) - client.use_ssl = true if uri.port.to_s == "443" + client.use_ssl = uri.scheme == 'https' client.read_timeout = opts[:timeout_seconds] || 10 client end diff --git a/spec/tripod/streaming_spec.rb b/spec/tripod/streaming_spec.rb index 4e08cd2..74bc8b0 100644 --- a/spec/tripod/streaming_spec.rb +++ b/spec/tripod/streaming_spec.rb @@ -58,13 +58,24 @@ end end - context 'https URI with default https port' do - let(:client) { Tripod::Streaming.create_http_client(URI('https://localhost:443/sparql/query'), {}) } + context 'https URI with default port' do + let(:client) { Tripod::Streaming.create_http_client(URI('https://localhost/sparql/query'), {}) } it 'should use ssl' do expect(client.use_ssl?).to eq(true) end end + context 'https with non-default port' do + let(:client) { Tripod::Streaming.create_http_client(URI('https://localhost:4433/sparql/query'), {}) } + it 'should use ssl' do + expect(client.use_ssl?).to eq(true) + end + + it 'should use specified port' do + expect(client.port).to eq(4433) + end + end + context 'with read timeout option' do let(:read_timeout) { 5 } let(:client) { Tripod::Streaming.create_http_client(URI('http://localhost/sparql/query'), {:timeout_seconds => read_timeout}) }