Sha256: 4b54cab0026fae6bc9b58aee4cc21c8b4b1b9439b786df313e5b0cb232aa3348

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

module FinApps
  module Middleware

    class ResponseLogger < Faraday::Response::Middleware
      include FinApps::Logging

      def call(env)
        logger.info "##{__method__.to_s} => ##{env.method} #{env.url.to_s}"
        logger.debug "##{__method__.to_s} => Request Headers: #{dump_headers env.request_headers}"

        super
      end

      def on_complete(env)
        logger.info "##{__method__.to_s} => ##{env.method} #{env.url.to_s}"
        logger.debug "##{__method__.to_s} => Response Headers: #{dump_headers env.response_headers}"
        logger.info "##{__method__.to_s} => Response Body: #{env.body}" if env.body
      end

      private
      def dump_headers(headers)
        headers.map { |k, v| "  #{k}: #{filter_sensitive_header_values(k,v)}" }.join(' ')
      end

      def filter_sensitive_header_values(key, value)
        case key
          when 'X-FinApps-Token', 'Authorization'
            '[REDACTED]'
          else
            value.inspect
        end
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
finapps-0.18.3.pre lib/finapps/middleware/response_logger.rb