Sha256: 9ae8f50d81a2347182a24c6e7024933176606847a959df9a72b9893eb98f0577

Contents?: true

Size: 969 Bytes

Versions: 87

Compression:

Stored size: 969 Bytes

Contents

require "net/https"
require "multi_json"

module CFoundry
  module TraceHelpers

    def request_trace(request)
      return nil unless request
      info = ["REQUEST: #{request[:method]} #{request[:url]}"]
      info << "REQUEST_HEADERS:"
      info << header_trace(request[:headers])
      info << "REQUEST_BODY: #{request[:body]}" if request[:body]
      info.join("\n")
    end


    def response_trace(response)
      return nil unless response
      info = ["RESPONSE: [#{response[:status]}]"]
      info << "RESPONSE_HEADERS:"
      info << header_trace(response[:headers])
      info << "RESPONSE_BODY:"
      begin
        parsed_body = MultiJson.load(response[:body])
        info << MultiJson.dump(parsed_body, :pretty => true)
      rescue
        info << "#{response[:body]}"
      end
      info.join("\n")
    end

    private

    def header_trace(headers)
      headers.sort.map do |key, value|
        "  #{key} : #{value}"
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 3 rubygems

Version Path
cfoundry-2.3.4 lib/cfoundry/trace_helpers.rb
cfoundry-2.3.3 lib/cfoundry/trace_helpers.rb
cfoundry-2.3.2 lib/cfoundry/trace_helpers.rb
cfoundry-2.3.1 lib/cfoundry/trace_helpers.rb
cfoundry-2.3.0 lib/cfoundry/trace_helpers.rb
cfoundry-2.2.0rc3 lib/cfoundry/trace_helpers.rb
cfoundry-2.2.0.rc2 lib/cfoundry/trace_helpers.rb
cfoundry-2.2.0.rc1 lib/cfoundry/trace_helpers.rb
cfoundry-2.1.2.rc1 lib/cfoundry/trace_helpers.rb
cfoundry-2.1.1 lib/cfoundry/trace_helpers.rb
cfoundry-2.1.0 lib/cfoundry/trace_helpers.rb
cfoundry-2.0.2 lib/cfoundry/trace_helpers.rb
cfoundry-2.0.1.rc1 lib/cfoundry/trace_helpers.rb
cfoundry-2.0.0 lib/cfoundry/trace_helpers.rb
cfoundry-1.5.3 lib/cfoundry/trace_helpers.rb
cfoundry-1.5.2 lib/cfoundry/trace_helpers.rb
cfoundry-1.5.1 lib/cfoundry/trace_helpers.rb
cfoundry-1.5.0 lib/cfoundry/trace_helpers.rb
cfoundry-1.4.0 lib/cfoundry/trace_helpers.rb
cfoundry-1.3.0 lib/cfoundry/trace_helpers.rb