Skip to content

Commit

Permalink
add support for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
saks committed Feb 6, 2020
1 parent 164423b commit 67779f5
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions lib/simple_segment/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def post(path, payload, headers: DEFAULT_HEADERS) # rubocop:disable Metrics/AbcS
status_code = nil
response_body = nil

uri = URI(BASE_URL)
payload = JSON.generate(payload)
if stub
logger.debug "stubbed request to \
Expand All @@ -31,32 +32,19 @@ def post(path, payload, headers: DEFAULT_HEADERS) # rubocop:disable Metrics/AbcS

{ status: 200, error: nil }
else
request = Net::HTTP::Post.new(path, headers)
request.basic_auth write_key, nil
connection.request(request, payload).tap do |res|
status_code = res.code
response_body = res.body
response = res
response.value
Net::HTTP.start(uri.host, uri.port, :ENV, http_options) do |http|
request = Net::HTTP::Post.new(path, headers)
request.basic_auth write_key, nil
http.request(request, payload).tap do |res|
status_code = res.code
response_body = res.body
response = res
response.value
end
end
end
rescue StandardError => e
error_handler.call(status_code, response_body, e, response)
end

private

def connection
uri = URI(BASE_URL)

http = Net::HTTP.new(uri.host, uri.port)

http_options.each do |key, value|
writer = "#{key}="
http.public_send(writer, value) if http.respond_to? writer
end

http
end
end
end

0 comments on commit 67779f5

Please sign in to comment.