Class: Attach::Middleware
- Inherits:
-
Object
- Object
- Attach::Middleware
- Defined in:
- lib/attach/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
6 7 8 |
# File 'lib/attach/middleware.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/attach/middleware.rb', line 10 def call(env) if env['PATH_INFO'] =~ /\A\/attachment\/([a-f0-9\-]{36})\/(.*)/ if = Attach::Attachment.find_by_token($1) [200, { 'Content-Length' => .file_size.to_s, 'Content-Type' => .file_type, 'Cache-Control' => "#{.cache_type || 'private'}, immutable, maxage=#{.cache_max_age || 30.days.to_i}", 'Content-Disposition' => "#{.disposition || 'attachment'}; filename=\"#{.file_name}\"," }, [.binary]] else [404, {}, ["Attachment not found"]] end else @app.call(env) end end |