Class: CubaApi::Ext2MimeRack
- Inherits:
-
Object
- Object
- CubaApi::Ext2MimeRack
- Defined in:
- lib/cuba_api/ext2mime_rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, *allowed) ⇒ Ext2MimeRack
constructor
A new instance of Ext2MimeRack.
Constructor Details
#initialize(app, *allowed) ⇒ Ext2MimeRack
Returns a new instance of Ext2MimeRack.
3 4 5 6 |
# File 'lib/cuba_api/ext2mime_rack.rb', line 3 def initialize( app, *allowed) @app = app @allowed = allowed end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cuba_api/ext2mime_rack.rb', line 8 def call(env) ext = env[ 'PATH_INFO' ].sub( /.*\./, '' ) if ext && @allowed.member?( ext ) mime = Rack::Mime.mime_type( '.' + ext ) env[ 'PATH_INFO_ORIG' ] = env[ 'PATH_INFO' ].dup env[ 'HTTP_ACCEPT' ] = mime env[ 'PATH_INFO' ].sub!( /\..*/, '' ) end status, headers, body = @app.call(env) end |