Sha256: 8985ae6fb110d212079220f3b1619c7adfb70eb6d78566aeb3454cd6f346391a
Contents?: true
Size: 1.45 KB
Versions: 4
Compression:
Stored size: 1.45 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]].compact.join('?') 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
httplog-1.3.3 | lib/httplog/adapters/excon.rb |
httplog-1.3.2 | lib/httplog/adapters/excon.rb |
httplog-1.3.1 | lib/httplog/adapters/excon.rb |
httplog-1.3.0 | lib/httplog/adapters/excon.rb |