def to_response
response = begin
if !(request.head? || request.get?)
[405, method_not_allowed_headers, ["method not allowed"]]
elsif etag_matches?
[304, cache_headers, []]
else
job.apply
env['dragonfly.job'] = job
[
200,
success_headers,
(request.head? ? [] : job)
]
end
rescue Job::Fetch::NotFound => e
Dragonfly.warn(e.message)
[404, {"Content-Type" => "text/plain"}, ["Not found"]]
rescue RuntimeError => e
Dragonfly.warn("caught error - #{e.message}")
[500, {"Content-Type" => "text/plain"}, ["Internal Server Error"]]
end
log_response(response)
response
end