Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/be_gateway/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(params)
@login = params.fetch(:shop_id)
@password = params.fetch(:secret_key)
@url = params.fetch(:url)
@read_timeout = params[:options]&.delete(:read_timeout)
@opts = params[:options] || {}
@rack_app = params[:rack_app]
@passed_headers = params[:headers]
Expand All @@ -24,7 +25,7 @@ def initialize(params)

private

attr_reader :login, :password, :url, :rack_app, :version
attr_reader :login, :password, :url, :rack_app, :version, :read_timeout

DEFAULT_OPEN_TIMEOUT = 5
DEFAULT_TIMEOUT = 25
Expand Down Expand Up @@ -80,7 +81,7 @@ def failed_response
def connection
@connection ||= Faraday::Connection.new(url, opts || {}) do |conn|
conn.options[:open_timeout] ||= DEFAULT_OPEN_TIMEOUT
conn.options[:timeout] ||= DEFAULT_TIMEOUT
conn.options[:timeout] ||= read_timeout || DEFAULT_TIMEOUT
conn.proxy ||= proxy if proxy # we use ||= to keep proxy passed within options
conn.headers = headers
conn.request :json
Expand Down
1 change: 1 addition & 0 deletions spec/be_gateway/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
let(:proxy) { 'http://example.com' }

before { test_class.proxy = proxy }
before { params.merge!(options: { read_timeout: 60 }) }

it 'uses proxy' do
expect(subject.proxy.uri.to_s).to eq(proxy)
Expand Down