Sha256: 474e5942b0d9a729f7f20cb48673a29ff5cb9290e6b274f94f6dc439eee30dd9

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

require 'dav4rack'
require 'dav4rack/file_resource'

module Bcms
  class WebDavMiddleware

    def initialize(app, options={})
      @app = app
      @dav4rack = DAV4Rack::Handler.new(:root => Rails.root.to_s, :root_uri_path => '/', :log_to => [STDERR, Logger::DEBUG], :resource_class=>Bcms::WebDAV::Resource)
      @options = options

      unless @options[:subdomain]
        @options[:subdomain] = 'webdav'
      end
    end

    def call(env)
      request = Rack::Request.new(env)
      if is_webdav?(request)
        return @dav4rack.call(env)
      else
        @app.call(env)
      end
    end

    private

    # A request is WebDAV if it matches either the port or subdomain (exactly).
    def is_webdav?(request)
      return true if @options[:port] && request.port == @options[:port]
      return true if request.host.starts_with?("#{@options[:subdomain]}.")
      false
    end


    def log(message)
      Rails.logger.warn message
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bcms_webdav-1.0.4 lib/bcms_webdav/web_dav_middleware.rb
bcms_webdav-1.0.2 lib/bcms_webdav/web_dav_middleware.rb
bcms_webdav-1.0.1 lib/bcms_webdav/web_dav_middleware.rb
bcms_webdav-1.0.0 lib/bcms_webdav/web_dav_middleware.rb