Sha256: eedcb66b20a771c89f5541362d740a5f256578a899d1e1656d5ca35ebb3261b6

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

if defined?(Ethon)
  module Ethon
    class Easy

      attr_accessor :action_name

      module Http
        alias_method :orig_http_request, :http_request
        def http_request(url, action_name, options = {})
          @action_name = action_name # remember this for compact logging 
          if HttpLog.url_approved?(url)
            HttpLog.log_request(action_name, url)
            HttpLog.log_headers(options[:headers])
            HttpLog.log_data(options[:body]) #if action_name == :post
          end

          orig_http_request(url, action_name, options)
        end
      end

      module Operations
        alias_method :orig_perform, :perform
        def perform
          return orig_perform unless HttpLog.url_approved?(url)

          response_code = nil
          bm = Benchmark.realtime do
            reponse_code = orig_perform
          end

          # Not sure where the acutal status code is stored - so let's
          # extract it from the response header.
          status   = response_headers.scan(/HTTP\/... (\d{3})/).flatten.first
          encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
          content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
          HttpLog.log_compact(@action_name, @url, @return_code, bm)
          HttpLog.log_status(status)
          HttpLog.log_benchmark(bm)
          HttpLog.log_body(response_body, encoding, content_type)
          return_code
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
httplog-0.99.7 lib/httplog/adapters/ethon.rb
httplog-0.99.6 lib/httplog/adapters/ethon.rb
httplog-0.99.5 lib/httplog/adapters/ethon.rb
httplog-0.99.4 lib/httplog/adapters/ethon.rb
httplog-0.99.3 lib/httplog/adapters/ethon.rb
httplog-0.99.2 lib/httplog/adapters/ethon.rb
httplog-0.99.1 lib/httplog/adapters/ethon.rb
httplog-0.3.3 lib/httplog/adapters/ethon.rb
httplog-0.3.2 lib/httplog/adapters/ethon.rb
httplog-0.3.1 lib/httplog/adapters/ethon.rb
httplog-0.3.0 lib/httplog/adapters/ethon.rb