Skip to content

Commit

Permalink
Ensure that Rack::ETag doesn't buffer responses
Browse files Browse the repository at this point in the history
In rack/rack#1416 the Rack::ETag middleware changed it's behaviour
to buffer the response and calculate an ETag digest even though
the Cache-Control: no-cache header is set. This breaks the CSV
streaming responses so to avoid that we use the hack outlined in
rack/rack#1619 and set a Last-Modified header which triggers the
skip_caching? condition in the Rack::ETag middleware.
  • Loading branch information
pixeltrix committed Apr 2, 2020
1 parent 3e7f2c2 commit 46413a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/archived/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def set_file_headers
end

def set_streaming_headers
#nginx doc: Setting this to "no" will allow unbuffered responses suitable for Comet and HTTP streaming applications
headers['X-Accel-Buffering'] = 'no'
headers["X-Accel-Buffering"] = "no"
headers["Cache-Control"] ||= "no-cache"
headers["Last-Modified"] = Time.current.httpdate
headers.delete("Content-Length")
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def set_file_headers
end

def set_streaming_headers
#nginx doc: Setting this to "no" will allow unbuffered responses suitable for Comet and HTTP streaming applications
headers['X-Accel-Buffering'] = 'no'
headers["X-Accel-Buffering"] = "no"
headers["Cache-Control"] ||= "no-cache"
headers["Last-Modified"] = Time.current.httpdate
headers.delete("Content-Length")
end

Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/admin/archived/petitions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
end

it "sets the streaming headers" do
expect(response["Cache-Control"]).to match(/no-cache/)
expect(response["X-Accel-Buffering"]).to eq("no")
expect(response["Cache-Control"]).to match(/no-cache/)
expect(response["Last-Modified"]).to match(/\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT/)
end

it "sets the content disposition" do
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/admin/petitions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
end

it "sets the streaming headers" do
expect(response["Cache-Control"]).to match(/no-cache/)
expect(response["X-Accel-Buffering"]).to eq("no")
expect(response["Cache-Control"]).to match(/no-cache/)
expect(response["Last-Modified"]).to match(/\w{3}, \d{2} \w{3} \d{4} \d{2}:\d{2}:\d{2} GMT/)
end

it "sets the content disposition" do
Expand Down

0 comments on commit 46413a7

Please sign in to comment.