Class: Dragonfly::Response

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

Constant Summary

DEFAULT_FILENAME =
proc do

Instance Method Summary (collapse)

Constructor Details

- (Response) initialize(job, env)

Returns a new instance of 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

- (Object) to_response



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

- (Boolean) will_be_served?

Returns:

  • (Boolean)


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

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