lib/kiev/rack/request_logger.rb in kiev-4.1.0 vs lib/kiev/rack/request_logger.rb in kiev-4.2.0

- old
+ new

@@ -1,7 +1,9 @@ # frozen_string_literal: true +require "zlib" + module Kiev module Rack class RequestLogger ERROR_STATUS = 500 ERROR_HEADERS = [].freeze @@ -113,18 +115,26 @@ full_body = [] body.each do |str| full_body << str end data[:body] = full_body.join + if data[:body] && !data[:body].empty? && response.headers["Content-Encoding"] == "gzip" + begin + sio = StringIO.new(data[:body]) + gz = Zlib::GzipReader.new(sio) + data[:body] = gz.read + rescue Zlib::GzipFile::Error => err + data[:gzip_parse_error] = err.message + end + end end should_log_errors = config.log_request_error_condition.call(request, response) if should_log_errors && exception.is_a?(Exception) data[:error_class] = exception.class.name data[:error_message] = exception.message[0..5000] data[:error_backtrace] = Array(exception.backtrace).join(NEW_LINE)[0..5000] end - data end def extract_route(env) action_params = env["action_dispatch.request.parameters"]