Sha256: 9f0b65eeb4cf4e647933b2a677e679f7fca59f90080f4215b9bc6cd05e8725d5
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
httplog-1.2.1 | lib/httplog/adapters/excon.rb |
httplog-1.2.0 | lib/httplog/adapters/excon.rb |