Class: Dragonfly::Response

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

Constant Summary collapse

DEFAULT_FILENAME =
proc do |job, request|
  [job.basename, job.format].compact.join('.') if job.basename
end

Instance Method Summary collapse

Constructor Details

#initialize(job, env) ⇒ Response


10
11
12
13
# File 'lib/dragonfly/response.rb', line 10

def initialize(job, env)
  @job, @env = job, env
  @app = @job.app
end

Instance Method Details

#to_responseObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dragonfly/response.rb', line 15

def to_response
  if !(request.head? || request.get?)
    [405, method_not_allowed_headers, ["#{request.request_method} method not allowed"]]
  elsif etag_matches?
    [304, cache_headers, []]
  elsif request.head?
    job.apply
    env['dragonfly.job'] = job
    [200, success_headers, []]
  elsif request.get?
    job.apply
    env['dragonfly.job'] = job
    [200, success_headers, job]
  end
rescue DataStorage::DataNotFound, DataStorage::BadUID => e
  app.log.warn(e.message)
  [404, {"Content-Type" => 'text/plain'}, ['Not found']]
end

#will_be_served?Boolean


34
35
36
# File 'lib/dragonfly/response.rb', line 34

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