Class: Flightdeck::AssetsController

Inherits:
ActionController::Metal
  • Object
show all
Includes:
ActionController::Head
Defined in:
app/controllers/flightdeck/assets_controller.rb

Overview

Deliberately not an ApplicationController subclass: assets are immutable, digest-addressed and carry no data, so they are served without auth and without the cost of the full ActionController::Base stack.

Constant Summary collapse

CACHE_CONTROL =
"public, max-age=31536000, immutable"

Instance Method Summary collapse

Instance Method Details

#showObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/flightdeck/assets_controller.rb', line 12

def show
  entry = Flightdeck::Assets.find(params[:name])
  return head(:not_found) unless entry

  etag = %("#{entry["digest"]}")
  headers["Cache-Control"] = CACHE_CONTROL
  headers["ETag"] = etag
  headers["X-Content-Type-Options"] = "nosniff"

  return head(:not_modified) if stale_etag_match?(etag)

  body = Flightdeck::Assets.read(params[:name])
  return head(:not_found) unless body

  headers["Content-Type"] = entry["content_type"] || Flightdeck::Assets.content_type_for(entry["file"])
  self.status = 200
  self.response_body = body
end