about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorStefan Sundin <git@stefansundin.com>2024-01-27 17:23:00 -0800
committerEric Wong <bofh@yhbt.net>2024-02-01 07:17:42 +0000
commit6b0768f8791c5d6dd2e8a5aea0da76d46549477e (patch)
tree4e13b686f9afec6ea9f74c5cf0faaec597379cfd /lib
parent2991f00afa4e445214f3b997bb37cb746c01cd2d (diff)
downloadclogger-6b0768f8791c5d6dd2e8a5aea0da76d46549477e.tar.gz
Rack::Utils::HeaderHash will be removed in rack 3.1 so these changes mostly
address that. The initializer in Rack::Headers inherits from Hash, so
switching to the ::[] class method to achieve the same result.
Diffstat (limited to 'lib')
-rw-r--r--lib/clogger/pure.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb
index 4b38e90..156f11e 100644
--- a/lib/clogger/pure.rb
+++ b/lib/clogger/pure.rb
@@ -8,10 +8,15 @@ class Clogger
   attr_accessor :env, :status, :headers, :body
   attr_writer :body_bytes_sent, :start
 
-  def initialize(app, opts = {})
-    # trigger autoload to avoid thread-safety issues later on
+  RackHeaders = if Object.const_defined?("Rack::Headers")
+    # Rack >= 3.0
+    Rack::Headers
+  else
+    # Rack < 3.0
     Rack::Utils::HeaderHash
+  end
 
+  def initialize(app, opts = {})
     @app = app
     @logger = opts[:logger]
     path = opts[:path]
@@ -35,7 +40,7 @@ class Clogger
       raise TypeError, "app response not a 3 element Array: #{resp.inspect}"
     end
     status, headers, body = resp
-    headers = Rack::Utils::HeaderHash.new(headers) if @need_resp
+    headers = RackHeaders[headers] if @need_resp
     if @wrap_body
       @reentrant = env['rack.multithread'] if @reentrant.nil?
       wbody = @reentrant ? self.dup : self
@@ -91,6 +96,9 @@ private
 
   def byte_xs(s)
     s = s.dup
+    if s.is_a?(Array)
+      s = s.join("\n")
+    end
     s.force_encoding(Encoding::BINARY) if defined?(Encoding::BINARY)
     s.gsub!(/(['"\x00-\x1f\x7f-\xff])/) do |x|
       "\\x#{$1.unpack('H2').first.upcase}"