From ba3037d63e4fe8558b3c6f5b345017beea8509eb Mon Sep 17 00:00:00 2001 From: cconstantine Date: Fri, 16 Sep 2016 16:38:58 -0700 Subject: [PATCH] Freeze shared header object in rack response so the current response's rack headers don't show up in the next request. --- lib/sidekiq/web/action.rb | 6 +++--- lib/sidekiq/web/application.rb | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/sidekiq/web/action.rb b/lib/sidekiq/web/action.rb index 5b9c0a83..5adc91e5 100644 --- a/lib/sidekiq/web/action.rb +++ b/lib/sidekiq/web/action.rb @@ -2,9 +2,9 @@ module Sidekiq class WebAction - RACK_SESSION = 'rack.session' - TEXT_HTML = { "Content-Type" => "text/html", "Cache-Control" => "no-cache" } - APPLICATION_JSON = { "Content-Type" => "application/json", "Cache-Control" => "no-cache" } + RACK_SESSION = 'rack.session'.freeze + TEXT_HTML = { "Content-Type" => "text/html", "Cache-Control" => "no-cache" }.freeze + APPLICATION_JSON = { "Content-Type" => "application/json", "Cache-Control" => "no-cache" }.freeze attr_accessor :env, :block, :type diff --git a/lib/sidekiq/web/application.rb b/lib/sidekiq/web/application.rb index fc26f69a..c16b5fef 100644 --- a/lib/sidekiq/web/application.rb +++ b/lib/sidekiq/web/application.rb @@ -7,7 +7,7 @@ module Sidekiq CONTENT_LENGTH = "Content-Length".freeze CONTENT_TYPE = "Content-Type".freeze REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human) - NOT_FOUND = [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass" }, ["Not Found"]] + NOT_FOUND = [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass" }.freeze, ["Not Found"]] def initialize(klass) @klass = klass @@ -290,6 +290,8 @@ module Sidekiq [200, type_header, [resp]] end + resp[1] = resp[1].dup + resp[1][CONTENT_LENGTH] = resp[2].inject(0) { |l, p| l + p.bytesize }.to_s resp