Class: Dragonfly::Response
Instance Method Summary collapse
-
#initialize(job, env) ⇒ Response
constructor
A new instance of Response.
- #to_response ⇒ Object
- #will_be_served? ⇒ Boolean
Constructor Details
#initialize(job, env) ⇒ Response
Returns a new instance of Response.
7 8 9 10 |
# File 'lib/dragonfly/response.rb', line 7 def initialize(job, env) @job, @env = job, env @app = @job.app end |
Instance Method Details
#to_response ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dragonfly/response.rb', line 12 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.) [404, {"content-type" => "text/plain"}, ["Not found"]] rescue RuntimeError => e Dragonfly.warn("caught error - #{e.}") [500, {"content-type" => "text/plain"}, ["Internal Server Error"]] end log_response(response) response end |
#will_be_served? ⇒ Boolean
38 39 40 |
# File 'lib/dragonfly/response.rb', line 38 def will_be_served? request.get? && !etag_matches? end |