Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensure proper header transfer (except for cache control)

Samfc36f095a736
diff --git a/lib/hijack.rb b/lib/hijack.rb
index a8a1268fb1d..51a4659591e 100644
--- a/lib/hijack.rb
+++ b/lib/hijack.rb
@@ -23,6 +23,8 @@ module Hijack
io = hijack.call
+ original_headers = response.headers
+
Scheduler::Defer.later("hijack #{params["controller"]} #{params["action"]}") do
MethodProfiler.start(transfer_timings)
@@ -39,6 +41,12 @@ module Hijack
instance.response = response
instance.request = request_copy
+ original_headers&.each do |k, v|
+ # hash special handling so skip
+ if k != "Cache-Control"
+ instance.response.headers[k] = v
+ end
+ end
begin
instance.instance_eval(&blk)
@@ -68,13 +76,13 @@ module Hijack
status_string = Rack::Utils::HTTP_STATUS_CODES[response.status.to_i] || "Unknown"
io.write "#{response.status} #{status_string}\r\n"
- headers.each do |name, val|
- io.write "#{name}: #{val}\r\n"
- end
-
timings = MethodProfiler.stop
if timings && duration = timings[:total_duration]
- io.write "X-Runtime: #{"%0.6f" % duration}\r\n"
+ headers["X-Runtime"] = "#{"%0.6f" % duration}"
+ end
+
+ headers.each do |name, val|
+ io.write "#{name}: #{val}\r\n"
end
io.write "\r\n"
diff --git a/spec/components/hijack_spec.rb b/spec/components/hijack_spec.rb
index a9f92ef309b..7d3c0c3ad85 100644
--- a/spec/components/hijack_spec.rb
+++ b/spec/components/hijack_spec.rb
@@ -114,6 +114,16 @@ describe Hijack do
expect(headers).to eq(expected)
end
+ it "handles transfers headers" do
+ tester.response.headers["Hello-World"] = "sam"
+ tester.hijack_test do
+ expires_in 1.year
+ render body: "hello world", status: 402
+ end
+
+ expect(tester.io.string).to include("Hello-World: sam")
+ end
+
it "handles expires_in" do
tester.hijack_test do
expires_in 1.year