Sha256: 880e913713ffbeef42d595edc1ee3a1713f5a6495df9a136760a42a7c9ff1547

Contents?: true

Size: 761 Bytes

Versions: 2

Compression:

Stored size: 761 Bytes

Contents

module Netrecording
  module NetHTTP
    def self.extended(base) #:nodoc:
      base.class_eval do
        alias :alias_for_request :request

        # request is overridden and the request and response are stored as a hash that can be written to a cache file
        def request(req, body = nil, &block)
          response = alias_for_request(req, body)

          unless Netrecording.recording?
            yield response and return if block
            return response
          end

          path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
          Netrecording.records << { method: req.method, path: path, request: req, response: response }

          yield response if block
          response
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netrecording-0.1.2 lib/netrecording/http.rb
netrecording-0.1.1 lib/netrecording/http.rb