Sha256: 28905333678b492548ddaab4a9ed26602d8d655d9f576e25a496e5c4bdaf80cd

Contents?: true

Size: 1.27 KB

Versions: 12

Compression:

Stored size: 1.27 KB

Contents

module HttpStore
  module Middleware
    class RequestLog
      include HttpStore::Helpers::Storable

      STRING_LIMIT_SIZE = 30_000

      def initialize(app)
        @app = app
      end

      def call(env)
        status, headers, body = @app.call(env)
        [status, headers, body]
      ensure
        build_meta(env, status, headers, body)
        store_request
      end

      def build_meta(env, status, headers, body)
        request = ActionDispatch::Request.new(env)

        @meta = Hashie::Mash.new(format_req(request))
        @meta.merge!(format_rsp(status, headers, body))
      end

      def format_req(request)
        {
          url:          request.url,
          path:         request.path,
          http_method:  request.request_method,
          data:         request.params,
          client_type:  request.params[:client_type],
          is_system:    true,
          headers:      request.headers.select { |k, _v| k.start_with? 'HTTP_' }.to_h,
          query_params: request.query_parameters,
          force:        true,
        }
      end

      def format_rsp(status, headers, body)
        {
          status_code:      status,
          response_headers: headers,
          response:         body.try(:body) || body
        }
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
http_store-0.6.19 lib/http_store/middleware/request_log.rb
http_store-0.6.18 lib/http_store/middleware/request_log.rb
http_store-0.6.14 lib/http_store/middleware/request_log.rb
http_store-0.6.13 lib/http_store/middleware/request_log.rb
http_store-0.6.12 lib/http_store/middleware/request_log.rb
http_store-0.6.10 lib/http_store/middleware/request_log.rb
http_store-0.6.9 lib/http_store/middleware/request_log.rb
http_store-0.6.8 lib/http_store/middleware/request_log.rb
http_store-0.6.7 lib/http_store/middleware/request_log.rb
http_store-0.6.6 lib/http_store/middleware/request_log.rb
http_store-0.6.5 lib/http_store/middleware/request_log.rb
http_store-0.6.4 lib/http_store/middleware/request_log.rb