Browse Source

[ruby/rack] Don't set redundant Content-Length header (#9015)

This header already gets set by all servers except Unicorn.
Petrik de Heus 1 year ago
parent
commit
dcbfae85be
1 changed files with 7 additions and 6 deletions
  1. 7 6
      frameworks/Ruby/rack/hello_world.rb

+ 7 - 6
frameworks/Ruby/rack/hello_world.rb

@@ -65,14 +65,15 @@ class HelloWorld
   end
   end
 
 
   def respond(content_type, body = '')
   def respond(content_type, body = '')
+    headers = {
+      CONTENT_TYPE => content_type,
+      DATE => Time.now.utc.httpdate,
+      SERVER => SERVER_STRING
+    }
+    headers[CONTENT_LENGTH] = body.bytesize.to_s if defined?(Unicorn)
     [
     [
       200,
       200,
-      {
-        CONTENT_TYPE => content_type,
-        DATE => Time.now.utc.httpdate,
-        SERVER => SERVER_STRING,
-        CONTENT_LENGTH => body.bytesize.to_s
-      },
+      headers,
       [body]
       [body]
     ]
     ]
   end
   end