dav4rack 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,7 +80,7 @@ lets continue with the last example but this time include the interceptor:
80
80
  end
81
81
  map '/' do
82
82
  use DAV4Rack::Interceptor, :mappings => {
83
- '/webdav/share/' => {:resource_class => FileResource, :options => {:custom => 'option'}},
83
+ '/webdav/share/' => {:resource_class => FileResource, :custom => 'option'},
84
84
  '/webdav/share2/' => {:resource_class => CustomResource}
85
85
  }
86
86
  use Rails::Rack::Static
@@ -96,6 +96,16 @@ resources have been reached, authentication will be enforced based on the requir
96
96
  note in the root map you can see we are running a Rails application. This is how you can easily enable DAV4Rack with your Rails
97
97
  application.
98
98
 
99
+ === Enabling Logging
100
+
101
+ DAV4Rack provides some simple logging in a Rails style format (simply for consistency) so the output should look some what familiar.
102
+
103
+ DAV4Rack::Handler.new(:resource_class => CustomResource, :log_to => '/my/log/file')
104
+
105
+ You can even specify the level of logging:
106
+
107
+ DAV4Rack::Handler.new(:resource_class => CustomResource, :log_to => ['/my/log/file', Logger::DEBUG])
108
+
99
109
  == Custom Resources
100
110
 
101
111
  Creating your own resource is easy. Simply inherit the DAV4Rack::Resource class, and start redefining all the methods
@@ -29,6 +29,7 @@ lib/dav4rack/interceptor_resource.rb
29
29
  lib/dav4rack/remote_file.rb
30
30
  lib/dav4rack/lock.rb
31
31
  lib/dav4rack/lock_store.rb
32
+ lib/dav4rack/logger.rb
32
33
  bin/dav4rack
33
34
  spec/handler_spec.rb
34
35
  README.rdoc
@@ -9,5 +9,5 @@ require 'dav4rack/handler'
9
9
  require 'dav4rack/controller'
10
10
 
11
11
  module DAV4Rack
12
- VERSION = '0.1.0'
12
+ VERSION = '0.1.1'
13
13
  end
@@ -1,3 +1,5 @@
1
+ require 'dav4rack/logger'
2
+
1
3
  module DAV4Rack
2
4
 
3
5
  class Handler
@@ -9,10 +11,11 @@ module DAV4Rack
9
11
  @options[:resource_class] = FileResource
10
12
  @options[:root] ||= Dir.pwd
11
13
  end
14
+ Logger.set(*@options[:log_to])
12
15
  end
13
16
 
14
17
  def call(env)
15
-
18
+ start = Time.now
16
19
  request = Rack::Request.new(env)
17
20
  response = Rack::Response.new
18
21
 
@@ -28,6 +31,9 @@ module DAV4Rack
28
31
  response.status = status.code
29
32
  rescue HTTPStatus::Status => status
30
33
  response.status = status.code
34
+ rescue Exception => e
35
+ Logger.error "WebDAV Error: #{e}\n#{e.backtrace.join("\n")}"
36
+ raise e
31
37
  end
32
38
 
33
39
  # Strings in Ruby 1.9 are no longer enumerable. Rack still expects the response.body to be
@@ -42,6 +48,9 @@ module DAV4Rack
42
48
  buf = true
43
49
  buf = request.body.read(8192) while buf
44
50
 
51
+ Logger.info "Processing WebDAV request: #{request.path} (for #{request.ip} at #{Time.now}) [#{request.request_method}]"
52
+ Logger.info "Completed in: #{((Time.now.to_f - start.to_f) * 1000).to_i} ms | #{response.status} [#{request.url}]"
53
+
45
54
  response.finish
46
55
  end
47
56
 
@@ -12,7 +12,7 @@ module DAV4Rack
12
12
  method = env['REQUEST_METHOD'].upcase
13
13
  app = nil
14
14
  if(@roots.detect{|x| path =~ /^#{Regexp.escape(x.downcase)}\/?/}.nil? && %w(OPTIONS PUT PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK).include?(method))
15
- app = DAV4Rack::Handler.new(:resource_class => InterceptorResource, :mappings => @args[:mappings])
15
+ app = DAV4Rack::Handler.new(:resource_class => InterceptorResource, :mappings => @args[:mappings], :log_to => @args[:log_to])
16
16
  end
17
17
  app ? app.call(env) : @app.call(env)
18
18
  end
@@ -99,7 +99,7 @@ module DAV4Rack
99
99
  new_public.slice!(-1) if new_public[-1,1] == '/'
100
100
  new_public = "#{new_public}#{name}"
101
101
  if(key = @root_paths.find{|x| new_path =~ /^#{Regexp.escape(x.downcase)}\/?/})
102
- @mappings[key][:resource_class].new(new_public, new_path.gsub(key, ''), request, response, {:root_uri_path => key, :user => @user}.merge(@mappings[key][:options] ? @mappings[key][:options] : options))
102
+ @mappings[key][:resource_class].new(new_public, new_path.gsub(key, ''), request, response, {:root_uri_path => key, :user => @user}.merge(options).merge(@mappings[key]))
103
103
  else
104
104
  self.class.new(new_public, new_path, request, response, {:user => @user}.merge(options))
105
105
  end
@@ -0,0 +1,24 @@
1
+ require 'logger'
2
+
3
+ module DAV4Rack
4
+ # This is a simple wrapper for the Logger class. It allows easy access
5
+ # to log messages from the library.
6
+ class Logger
7
+ class << self
8
+ # args:: Arguments for Logger -> [path, level] (level is optional)
9
+ # Set the path to the log file.
10
+ def set(*args)
11
+ @@logger = ::Logger.new(args.first, 'weekly')
12
+ if(args.size > 1)
13
+ @@logger.level = args[1]
14
+ end
15
+ end
16
+
17
+ def method_missing(*args)
18
+ if(defined? @@logger)
19
+ @@logger.send *args
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -402,7 +402,7 @@ module DAV4Rack
402
402
  # TODO: Add support for digest
403
403
  def auth_credentials
404
404
  auth = Rack::Auth::Basic::Request.new(request.env)
405
- auth.basic? && auth.credentials ? auth.credentials : [nil,nil]
405
+ auth.provided? && auth.basic? ? auth.credentials : [nil,nil]
406
406
  end
407
407
 
408
408
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dav4rack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-10 00:00:00 -07:00
18
+ date: 2010-08-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,7 @@ files:
73
73
  - lib/dav4rack/remote_file.rb
74
74
  - lib/dav4rack/lock.rb
75
75
  - lib/dav4rack/lock_store.rb
76
+ - lib/dav4rack/logger.rb
76
77
  - bin/dav4rack
77
78
  - spec/handler_spec.rb
78
79
  - README.rdoc