lib/dav4rack/resource.rb in dav4rack-0.2.10 vs lib/dav4rack/resource.rb in dav4rack-0.2.11
- old
+ new
@@ -14,11 +14,12 @@
@path_status[path] = status
end
end
class Resource
- attr_reader :path, :options, :public_path, :request, :response
+ attr_reader :path, :options, :public_path, :request,
+ :response, :propstat_relative_path, :root_xml_attributes
attr_accessor :user
@@blocks = {}
class << self
@@ -69,10 +70,12 @@
:public_path, :request, :response, :user,
:user=, :setup
]
@public_path = public_path.dup
@path = path.dup
+ @propstat_relative_path = !!options.delete(:propstat_relative_path)
+ @root_xml_attributes = options.delete(:root_xml_attributes) || {}
@request = request
@response = response
unless(options.has_key?(:lock_class))
require 'dav4rack/lock_store'
@lock_class = LockStore
@@ -135,42 +138,43 @@
parent.exist?
end
# Return the creation time.
def creation_date
- NotImplemented
+ raise NotImplemented
end
# Return the time of last modification.
def last_modified
- NotImplemented
+ raise NotImplemented
end
# Set the time of last modification.
def last_modified=(time)
- NotImplemented
+ # Is this correct?
+ raise NotImplemented
end
# Return an Etag, an unique hash value for this resource.
def etag
- NotImplemented
+ raise NotImplemented
end
# Return the resource type. Generally only used to specify
# resource is a collection.
def resource_type
:collection if collection?
end
# Return the mime type of this resource.
def content_type
- NotImplemented
+ raise NotImplemented
end
# Return the size in bytes for this resource.
def content_length
- NotImplemented
+ raise NotImplemented
end
# HTTP GET request.
#
# Write the content of the resource to the response.body.
@@ -345,11 +349,11 @@
# Returns the value of the given property
def get_property(name)
case name
when 'resourcetype' then resource_type
when 'displayname' then display_name
- when 'creationdate' then creation_date.xmlschema
+ when 'creationdate' then use_ms_compat_creationdate? ? creation_date.httpdate : creation_date.xmlschema
when 'getcontentlength' then content_length.to_s
when 'getcontenttype' then content_type
when 'getetag' then etag
when 'getlastmodified' then last_modified.httpdate
end
@@ -363,12 +367,10 @@
when 'resourcetype' then self.resource_type = value
when 'getcontenttype' then self.content_type = value
when 'getetag' then self.etag = value
when 'getlastmodified' then self.last_modified = Time.httpdate(value)
end
- rescue ArgumentError
- Conflict
end
# name:: Property name
# Remove the property from the resource
def remove_property(name)
@@ -388,13 +390,21 @@
self.class.new("#{new_public}#{name}", "#{new_path}#{name}", request, response, options.merge(:user => @user))
end
# Return parent of this resource
def parent
- elements = @path.scan(/[^\/]+/)
- return nil if elements.empty?
- self.class.new(('/' + @public_path.scan(/[^\/]+/)[0..-2].join('/')), ('/' + elements[0..-2].to_a.join('/')), @request, @response, @options.merge(:user => @user))
+ unless(@path.to_s.empty?)
+ self.class.new(
+ File.split(@public_path).first,
+ File.split(@path).first,
+ @request,
+ @response,
+ @options.merge(
+ :user => @user
+ )
+ )
+ end
end
# Return list of descendants
def descendants
list = []
@@ -403,12 +413,10 @@
list.concat(child.descendants)
end
list
end
- protected
-
# Index page template for GETs on collection
def index_page
'<html><head> <title>%s</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /></head>
<body> <h1>%s</h1> <hr /> <table> <tr> <th class="name">Name</th>
@@ -423,13 +431,33 @@
def allows_redirect?
[
%r{cyberduck}i,
%r{konqueror}i
].any? do |regexp|
- (request.respond_to?(:user_agent) ? request.user_agent : request.env['HTTP_USER_AGENT']) =~ regexp
+ (request.respond_to?(:user_agent) ? request.user_agent : request.env['HTTP_USER_AGENT']).to_s =~ regexp
end
end
-
+
+ def use_compat_mkcol_response?
+ @options[:compat_mkcol] || @options[:compat_all]
+ end
+
+ # Returns true if using an MS client
+ def use_ms_compat_creationdate?
+ if(@options[:compat_ms_mangled_creationdate] || @options[:compat_all])
+ is_ms_client?
+ end
+ end
+
+ # Basic user agent testing for MS authored client
+ def is_ms_client?
+ [%r{microsoft-webdav}i, %r{microsoft office}i].any? do |regexp|
+ (request.respond_to?(:user_agent) ? request.user_agent : request.env['HTTP_USER_AGENT']).to_s =~ regexp
+ end
+ end
+
+ protected
+
# Returns authentication credentials if available in form of [username,password]
# TODO: Add support for digest
def auth_credentials
auth = Rack::Auth::Basic::Request.new(request.env)
auth.provided? && auth.basic? ? auth.credentials : [nil,nil]