Class: Paltrow::Rendering::Rails::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/paltrow/rendering/rails/stream.rb

Instance Method Summary collapse

Instance Method Details

#call(handler:, page:) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/paltrow/rendering/rails/stream.rb', line 48

def call handler:, page:
  handler.response.headers["Content-Disposition"] = ContentDisposition.format(
    disposition: "attachment",
    filename: page.locals.fetch(:filename)
  )
  handler.response.delete_header "Content-Length"
  handler.response.headers["Cache-Control"] = "no-cache"
  handler.response.headers["Last-Modified"] = Time.now.httpdate.to_s
  handler.response.headers["X-Accel-Buffering"] = "no"

  begin
    page
      .locals
      .fetch(:content_stream)
      .each_chunk { |chunk| handler.response.stream.write(chunk) }
  ensure
    handler.response.stream.close
  end
end