10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/csb/handler.rb', line 10
def self.call(template, source = nil)
source ||= template.source
<<~RUBY
csv = ::Csb::Template.new(
utf8_bom: ::Csb.configuration.utf8_bom,
streaming: ::Csb.configuration.streaming,
)
#{source}
controller.send(:send_file_headers!, type: 'text/csv', filename: csv.filename)
if csv.streaming?
response.headers['Cache-Control'] = 'no-cache'
response.headers['X-Accel-Buffering'] = 'no'
# SEE: https://github.com/rack/rack/issues/1619
if Gem::Version.new('2.2.0') <= Gem::Version.new(Rack::RELEASE)
response.headers['Last-Modified'] = '0'
end
end
csv.build
RUBY
end
|