Sha256: 840f1de915d197193750dd90f9d24faa767f71b0f12e8d8b5fd6d1cb397c8d6b

Contents?: true

Size: 788 Bytes

Versions: 17

Compression:

Stored size: 788 Bytes

Contents

require 'dav4rack/interceptor_resource'
module DAV4Rack
  class Interceptor
    def initialize(app, args={})
      @roots = args[:mappings].keys
      @args = args
      @app = app
      @intercept_methods = %w(OPTIONS PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK)
      @intercept_methods -= args[:ignore_methods] if args[:ignore_methods]
    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? && @intercept_methods.include?(method))
        app = DAV4Rack::Handler.new(:resource_class => InterceptorResource, :mappings => @args[:mappings], :log_to => @args[:log_to])
      end
      app ? app.call(env) : @app.call(env)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
dav4rack-0.3.0 lib/dav4rack/interceptor.rb
dav4rack-0.2.11 lib/dav4rack/interceptor.rb
dav4rack-0.2.10 lib/dav4rack/interceptor.rb
dav4rack-0.2.9 lib/dav4rack/interceptor.rb
dav4rack-0.2.8 lib/dav4rack/interceptor.rb
dav4rack-0.2.7 lib/dav4rack/interceptor.rb
dav4rack-0.2.6 lib/dav4rack/interceptor.rb
dav4rack-0.2.5 lib/dav4rack/interceptor.rb
dav4rack-0.2.4 lib/dav4rack/interceptor.rb
dav4rack-0.2.3 lib/dav4rack/interceptor.rb
dav4rack-0.2.2 lib/dav4rack/interceptor.rb
dav4rack-0.2.1 lib/dav4rack/interceptor.rb
dav4rack-0.2.0 lib/dav4rack/interceptor.rb
dav4rack-0.1.8 lib/dav4rack/interceptor.rb
dav4rack-0.1.7 lib/dav4rack/interceptor.rb
dav4rack-0.1.6 lib/dav4rack/interceptor.rb
dav4rack-0.1.5 lib/dav4rack/interceptor.rb