Set DAV compliance at the Resource
This commit is contained in:
@@ -29,6 +29,7 @@ module Calligraphy::Rails
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Prevent any request with `.` or `..` as part of the resource ID.
|
||||||
def verify_resource_scope
|
def verify_resource_scope
|
||||||
head :forbidden if %w(. ..).any? { |seg| params[:resource].include? seg }
|
head :forbidden if %w(. ..).any? { |seg| params[:resource].include? seg }
|
||||||
end
|
end
|
||||||
@@ -52,6 +53,7 @@ module Calligraphy::Rails
|
|||||||
|
|
||||||
@resource_class = params[:resource_class] || Calligraphy::Resource
|
@resource_class = params[:resource_class] || Calligraphy::Resource
|
||||||
@resource_root_path = params[:resource_root_path]
|
@resource_root_path = params[:resource_root_path]
|
||||||
|
|
||||||
@resource = @resource_class.new resource: resource_id, req: request, root_dir: @resource_root_path
|
@resource = @resource_class.new resource: resource_id, req: request, root_dir: @resource_root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -137,6 +139,7 @@ module Calligraphy::Rails
|
|||||||
|
|
||||||
def validate_etag(etag_validators, validate_against)
|
def validate_etag(etag_validators, validate_against)
|
||||||
cache_key = ActiveSupport::Cache.expand_cache_key etag_validators
|
cache_key = ActiveSupport::Cache.expand_cache_key etag_validators
|
||||||
|
|
||||||
"W/\"#{Digest::MD5.hexdigest(cache_key)}\"" == validate_against
|
"W/\"#{Digest::MD5.hexdigest(cache_key)}\"" == validate_against
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -156,7 +159,8 @@ module Calligraphy::Rails
|
|||||||
end
|
end
|
||||||
|
|
||||||
def options
|
def options
|
||||||
response.headers['DAV'] = '1, 2, 3'
|
response.headers['DAV'] = @resource.dav_compliance
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ module Calligraphy
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dav_compliance
|
||||||
|
'1, 2, 3'
|
||||||
|
end
|
||||||
|
|
||||||
def delete_collection
|
def delete_collection
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,5 +29,12 @@ RSpec.describe 'Resource' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#dav_compliance' do
|
||||||
|
it 'advertises full WebDAV compliance' do
|
||||||
|
resource = Calligraphy::Resource.new
|
||||||
|
expect(resource.dav_compliance).to eq('1, 2, 3')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user