Sha256: c4078e27482c65251b7fc9775e1559ad6b2f669aa1433f7535b8f521c0a38bba
Contents?: true
Size: 796 Bytes
Versions: 3
Compression:
Stored size: 796 Bytes
Contents
module Nifty module Attachments class Middleware def initialize(app) @app = app end def call(env) if env['PATH_INFO'] =~ /\A\/attachment\/([a-f0-9\-]{36})\/(.*)/ if attachment = Nifty::Attachments::Attachment.find_by_token($1) [200, { 'Content-Length' => attachment.data.bytesize.to_s, 'Content-Type' => attachment.file_type, 'Cache-Control' => "public, maxage=#{1.year.to_i}", 'Content-Disposition' => "attachment; filename=\"#{attachment.file_name}\"" }, [attachment.data]] else [404, {}, ["Attachment not found"]] end else @app.call(env) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nifty-attachments-1.0.3 | lib/nifty/attachments/middleware.rb |
nifty-attachments-1.0.1 | lib/nifty/attachments/middleware.rb |
nifty-attachments-1.0.0 | lib/nifty/attachments/middleware.rb |