Sha256: 1603191b71a5422272420b456ec5b60c7c309a1297155909585fe27fe49b1b8b

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

if defined?(::HTTPClient)
  class HTTPClient
    private
    alias_method :orig_do_get_block, :do_get_block

    def do_get_block(req, proxy, conn, &block)
      log_enabled = HttpLog.url_approved?(req.header.request_uri)

      if log_enabled
        HttpLog.log_request(req.header.request_method, req.header.request_uri)
        HttpLog.log_headers(req.headers)
        HttpLog.log_data(req.body)# if req.header.request_method == "POST"
      end

      retryable_response = nil
      bm = Benchmark.realtime do
        begin
          orig_do_get_block(req, proxy, conn, &block)
        rescue RetryableResponse => e
          retryable_response = e
        end
      end

      if log_enabled
        res = conn.pop
        HttpLog.log_compact(req.header.request_method, req.header.request_uri, res.status_code, bm)
        HttpLog.log_status(res.status_code)
        HttpLog.log_benchmark(bm)
        HttpLog.log_body(res.body)
        conn.push(res)
      end

      raise retryable_response if retryable_response != nil
    end

    class Session
      alias_method :orig_create_socket, :create_socket
      def create_socket(site)
        if HttpLog.url_approved?("#{site.host}:#{site.port}")
          HttpLog.log_connection(site.host, site.port)
        end
        orig_create_socket(site)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
httplog-0.2.11 lib/httplog/adapters/httpclient.rb
httplog-0.2.10 lib/httplog/adapters/httpclient.rb
httplog-0.2.9 lib/httplog/adapters/httpclient.rb