Sha256: caab9e1b308547f5caf1019df729f5eea517cae5e282809075cfeda279a1af03

Contents?: true

Size: 644 Bytes

Versions: 2

Compression:

Stored size: 644 Bytes

Contents

require 'dav4rack/interceptor_resource'
module DAV4Rack
  class Interceptor
    def initialize(app, args={})
      @roots = args[:mappings].keys
      @args = args
      @app = app
    end

    def call(env)
      path = env['PATH_INFO'].downcase
      method = env['REQUEST_METHOD'].upcase
      app = nil
      if(@roots.detect{|x| path =~ /^#{Regexp.escape(x.downcase)}\/?/}.nil? && %w(OPTIONS PUT PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK).include?(method))
        app = DAV4Rack::Handler.new(:resource_class => InterceptorResource, :mappings => @args[:mappings])
      end
      app ? app.call(env) : @app.call(env)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dav4rack-0.1.0 lib/dav4rack/interceptor.rb
dav4rack-0.0.1 lib/dav4rack/interceptor.rb