Class: BitsService::LoggingHttpClient
- Inherits:
-
Object
- Object
- BitsService::LoggingHttpClient
- Defined in:
- lib/bits_service_client/logging_http_client.rb
Instance Method Summary collapse
- #delete(path, vcap_request_id) ⇒ Object
- #do_request(request, vcap_request_id) ⇒ Object
- #get(path, vcap_request_id, credentials = nil) ⇒ Object
- #head(path, vcap_request_id) ⇒ Object
-
#initialize(http_client) ⇒ LoggingHttpClient
constructor
A new instance of LoggingHttpClient.
- #put(path, body, vcap_request_id) ⇒ Object
Constructor Details
#initialize(http_client) ⇒ LoggingHttpClient
Returns a new instance of LoggingHttpClient.
7 8 9 10 11 |
# File 'lib/bits_service_client/logging_http_client.rb', line 7 def initialize(http_client) @http_client = http_client @logger = Steno.logger('cc.bits_service_client') @statsd = Statsd.new end |
Instance Method Details
#delete(path, vcap_request_id) ⇒ Object
29 30 31 |
# File 'lib/bits_service_client/logging_http_client.rb', line 29 def delete(path, vcap_request_id) do_request(Net::HTTP::Delete.new(path), vcap_request_id) end |
#do_request(request, vcap_request_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bits_service_client/logging_http_client.rb', line 33 def do_request(request, vcap_request_id) @logger.info('Request', { method: request.method, path: request.path, address: @http_client.address, port: @http_client.port, vcap_request_id: vcap_request_id, }) request.add_field('X-VCAP-REQUEST-ID', vcap_request_id) begin response = @http_client.request(request) @logger.info('Response', { code: response.code, vcap_request_id: vcap_request_id }) rescue Net::ReadTimeout => ex @statsd.increment("cc.bits_#{request.method.downcase}.timeout") @logger.info('Request timeout', { method: request.method, path: request.path, address: @http_client.address, port: @http_client.port, vcap_request_id: vcap_request_id, }) raise ex end response end |
#get(path, vcap_request_id, credentials = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/bits_service_client/logging_http_client.rb', line 13 def get(path, vcap_request_id, credentials=nil) req = Net::HTTP::Get.new(path) if credentials req.basic_auth(credentials[:username], credentials[:password]) end do_request(req, vcap_request_id) end |
#head(path, vcap_request_id) ⇒ Object
21 22 23 |
# File 'lib/bits_service_client/logging_http_client.rb', line 21 def head(path, vcap_request_id) do_request(Net::HTTP::Head.new(path), vcap_request_id) end |
#put(path, body, vcap_request_id) ⇒ Object
25 26 27 |
# File 'lib/bits_service_client/logging_http_client.rb', line 25 def put(path, body, vcap_request_id) do_request(Net::HTTP::Put::Multipart.new(path, body), vcap_request_id) end |