Class: Dragonfly::Response

Inherits:
Object show all
Defined in:
lib/dragonfly/response.rb

Instance Method Summary collapse

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_responseObject



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.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

#will_be_served?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/dragonfly/response.rb', line 38

def will_be_served?
  request.get? && !etag_matches?
end