Browse Source

[ruby/rack] Fix and enable fortunes (#8513)

Also use bytesize for the Content-Length header to make sure non ASCII
characters are are correctly added to the total length.
Petrik de Heus 1 year ago
parent
commit
0a01e1f36f
2 changed files with 8 additions and 5 deletions
  1. 4 0
      frameworks/Ruby/rack/benchmark_config.json
  2. 4 5
      frameworks/Ruby/rack/hello_world.rb

+ 4 - 0
frameworks/Ruby/rack/benchmark_config.json

@@ -7,6 +7,7 @@
         "plaintext_url": "/plaintext",
         "db_url": "/db",
         "query_url": "/queries?queries=",
+        "fortune_url": "/fortunes",
         "update_url": "/updates?queries=",
         "port": 8080,
         "approach": "Stripped",
@@ -27,6 +28,7 @@
         "plaintext_url": "/plaintext",
         "db_url": "/db",
         "query_url": "/queries?queries=",
+        "fortune_url": "/fortunes",
         "update_url": "/updates?queries=",
         "port": 8080,
         "approach": "Stripped",
@@ -47,6 +49,7 @@
         "plaintext_url": "/plaintext",
         "db_url": "/db",
         "query_url": "/queries?queries=",
+        "fortune_url": "/fortunes",
         "update_url": "/updates?queries=",
         "port": 8080,
         "approach": "Stripped",
@@ -67,6 +70,7 @@
         "plaintext_url": "/plaintext",
         "db_url": "/db",
         "query_url": "/queries?queries=",
+        "fortune_url": "/fortunes",
         "update_url": "/updates?queries=",
         "port": 8080,
         "approach": "Stripped",

+ 4 - 5
frameworks/Ruby/rack/hello_world.rb

@@ -41,7 +41,7 @@ class HelloWorld
   TEMPLATE_PREFIX = '<!DOCTYPE html>
 <html>
 <head>
-  <title>Fortune</title>
+  <title>Fortunes</title>
 </head>
 <body>
   <table>
@@ -50,7 +50,7 @@ class HelloWorld
       <th>message</th>
     </tr>'
   TEMPLATE_POSTFIX = '</table>
-    </body
+    </body>
   </html>'
 
   def initialize
@@ -66,8 +66,7 @@ class HelloWorld
         CONTENT_TYPE => content_type,
         DATE => Time.now.utc.httpdate,
         SERVER => SERVER_STRING,
-        CONTENT_LENGTH => body.length.to_s
-
+        CONTENT_LENGTH => body.bytesize.to_s
       },
       [body]
     ]
@@ -81,7 +80,7 @@ class HelloWorld
     buffer << TEMPLATE_PREFIX
 
     fortunes.each do |item|
-      buffer << "<tr><td> #{item[:id]} </td> <td>#{Rack::Utils.escape_html(item[:message])}</td></tr>"
+      buffer << "<tr><td>#{item[:id]}</td><td>#{Rack::Utils.escape_html(item[:message])}</td></tr>"
     end
     buffer << TEMPLATE_POSTFIX
   end