Sha256: 053abd9f0499ecf1e470c5b6cc0751bf81088924e27d5c9b7dc571d6b5eccdf0

Contents?: true

Size: 550 Bytes

Versions: 2

Compression:

Stored size: 550 Bytes

Contents

module CubaApi
  module Rack
    class Ext2MimeRack
      def initialize( app, *allowed)
        @app = app
        @allowed = allowed
      end
      
      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cuba-api-0.6.3 lib/cuba_api/rack/ext2mime_rack.rb
cuba-api-0.6.2 lib/cuba_api/rack/ext2mime_rack.rb