Skip to content

Commit 011d754

Browse files
committed
Add proxy support to polling
1 parent 5afcdcd commit 011d754

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/ldclient-rb/requestor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def make_request(path)
3030
req.headers["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
3131
req.options.timeout = @config.read_timeout
3232
req.options.open_timeout = @config.connect_timeout
33+
if @config.proxy
34+
req.options.proxy = Faraday::ProxyOptions.from @config.proxy
35+
end
3336
end
3437

3538
@config.logger.debug("[LDClient] Got response from uri: #{uri}\n\tstatus code: #{res.status}\n\theaders: #{res.headers}\n\tbody: #{res.body}")

spec/requestor_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require "spec_helper"
2+
require "faraday"
3+
4+
describe LaunchDarkly::Requestor do
5+
describe ".request_all_flags" do
6+
describe "with a proxy" do
7+
let(:requestor) {
8+
LaunchDarkly::Requestor.new(
9+
"key",
10+
LaunchDarkly::Config.new({
11+
:proxy => "http://proxy.com",
12+
:base_uri => "http://ld.com"
13+
})
14+
)
15+
}
16+
it "converts the proxy option" do
17+
faraday = Faraday.new
18+
requestor.instance_variable_set(:@client, faraday)
19+
allow(faraday).to receive(:get) do |*args, &block|
20+
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
21+
block.call(req)
22+
expect(args).to eq ['http://ld.com/sdk/latest-flags']
23+
expect(req.options.proxy[:uri]).to eq URI("http://proxy.com")
24+
double(body: '{"foo": "bar"}', status: 200, headers: {})
25+
end
26+
27+
requestor.request_all_flags()
28+
end
29+
end
30+
describe "without a proxy" do
31+
let(:requestor) {
32+
LaunchDarkly::Requestor.new(
33+
"key",
34+
LaunchDarkly::Config.new({
35+
:base_uri => "http://ld.com"
36+
})
37+
)
38+
}
39+
it "converts the proxy option" do
40+
faraday = Faraday.new
41+
requestor.instance_variable_set(:@client, faraday)
42+
allow(faraday).to receive(:get) do |*args, &block|
43+
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
44+
block.call(req)
45+
expect(args).to eq ['http://ld.com/sdk/latest-flags']
46+
expect(req.options.proxy).to eq nil
47+
double(body: '{"foo": "bar"}', status: 200, headers: {})
48+
end
49+
requestor.request_all_flags()
50+
end
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)