Skip to content

Commit 06c3214

Browse files
committed
fix raising of ProxyError, add unit test
1 parent 228f3aa commit 06c3214

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/sse_client/streaming_http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def self.connect(uri, proxy, connect_timeout, read_timeout)
6161
# temporarily create a reader just for the proxy connect response
6262
proxy_reader = HTTPResponseReader.new(socket, read_timeout)
6363
if proxy_reader.status != 200
64-
throw ProxyError, "proxy connection refused, status #{proxy_reader.status}"
64+
raise ProxyError, "proxy connection refused, status #{proxy_reader.status}"
6565
end
6666

6767
# start using TLS at this point if appropriate

spec/sse_client/sse_shared.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def setup_response(uri_path, &action)
4242

4343
class StubProxyServer < StubHTTPServer
4444
attr_reader :request_count
45+
attr_accessor :connect_status
4546

4647
def initialize
4748
super
@@ -55,6 +56,9 @@ def create_server(port)
5556
AccessLog: [],
5657
Logger: NullLogger.new,
5758
ProxyContentHandler: proc do |req,res|
59+
if !@connect_status.nil?
60+
res.status = @connect_status
61+
end
5862
@request_count += 1
5963
end
6064
)

spec/sse_client/streaming_http_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ def with_connection(cxn)
118118
end
119119
end
120120

121+
it "throws error if proxy responds with error status" do
122+
with_server do |server|
123+
server.setup_response("/") do |req,res|
124+
res.body = body
125+
end
126+
with_server(StubProxyServer.new) do |proxy|
127+
proxy.connect_status = 403
128+
expect { subject.new(server.base_uri, proxy.base_uri, {}, 30, 30) }.to raise_error(SSE::ProxyError)
129+
end
130+
end
131+
end
132+
121133
# The following 2 tests were originally written to connect to an embedded HTTPS server made with
122134
# WEBrick. Unfortunately, some unknown problem prevents WEBrick's self-signed certificate feature
123135
# from working in JRuby 9.1 (but not in any other Ruby version). Therefore these tests currently

0 commit comments

Comments
 (0)