11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/pan_handler/middleware.rb', line 11
def call(env)
@request = Rack::Request.new(env)
@render_odt = false
set_request_to_render_as_odt(env) if render_as_odt?
status, , response = @app.call(env)
if rendering_odt? && ['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
body = response.respond_to?(:body) ? response.body : response.join
body = body.join if body.is_a?(Array)
body = PanHandler.new(translate_paths(body, env), @options).to_odt
response = [body]
.delete('ETag')
.delete('Cache-Control')
["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
["Content-Type"] = "application/vnd.oasis.opendocument.text"
end
[status, , response]
end
|