Sha256: ef06680d2c8f91072d49c1e114c5605eff37d83bec637a1426d68c4ad900712c
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true if defined?(Excon) module Excon module HttpLogHelper def httplog_url(datum) @httplog_url ||= "#{datum[:scheme]}://#{datum[:host]}:#{datum[:port]}#{datum[:path]}#{datum[:query]}" end end class Socket include Excon::HttpLogHelper alias orig_connect connect def connect host = @data[:proxy] ? @data[:proxy][:host] : @data[:host] port = @data[:proxy] ? @data[:proxy][:port] : @data[:port] HttpLog.log_connection(host, port) if ::HttpLog.url_approved?(httplog_url(@data)) orig_connect end end class Connection include Excon::HttpLogHelper attr_reader :bm alias orig_request request def request(params, &block) result = nil bm = Benchmark.realtime do result = orig_request(params, &block) end url = httplog_url(@data) return result unless HttpLog.url_approved?(url) headers = result[:headers] || {} HttpLog.call( method: params[:method], url: url, request_body: @data[:body], request_headers: @data[:headers] || {}, response_code: result[:status], response_body: result[:body], response_headers: headers, benchmark: bm, encoding: headers['Content-Encoding'], content_type: headers['Content-Type'] ) result end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
httplog-1.2.2 | lib/httplog/adapters/excon.rb |