Skip to content

Commit

Permalink
[ruby/roda-sequel] Only set headers not created by servers
Browse files Browse the repository at this point in the history
Servers like Iodine sets the `Date` header itself.

+------------------------------------+------+-----+-----+------+-------+---------+--------------+
|                         branch_name|  json|   db|query|update|fortune|plaintext|weighted_score|
+------------------------------------+------+-----+-----+------+-------+---------+--------------+
|                              master|213942|52774|37141| 22971|  49660|   227545|          2923|
|roda-sequel/remove-redundant-headers|280527|89348|61538| 24688|  57966|   335448|          3752|
+------------------------------------+------+-----+-----+------+-------+---------+--------------+
  • Loading branch information
p8 committed Jan 27, 2025
1 parent 523534b commit da1dc79
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions frameworks/Ruby/roda-sequel/hello_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ def rand1
rand(MAX_PK) + 1
end

if defined?(Puma) || defined?(Unicorn)
def set_default_headers(response)
response[DATE_HEADER] = Time.now.httpdate
response[SERVER_HEADER] = SERVER_STRING
end
else
def set_default_headers(response)
response[SERVER_HEADER] = SERVER_STRING
end
end

route do |r|
response[DATE_HEADER] = Time.now.httpdate
response[SERVER_HEADER] = SERVER_STRING if SERVER_STRING
set_default_headers(response)

# Test type 1: JSON serialization
r.is "json" do
Expand Down

0 comments on commit da1dc79

Please sign in to comment.