class Calligraphy::Rails::WebDavRequestsController
Controller for all WebDAV requests.
Public Instance Methods
invoke_method()
click to toggle source
Entry-point for all WebDAV requests. Handles checking and validating preconditions, directing of requests to the proper WebDAV action method, and composing responses to send back to the client.
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 17 def invoke_method unless check_preconditions return send_response(status: :precondition_failed) end method = request.request_method.downcase status, body = make_request method send_response status: status, body: body end
Private Instance Methods
authenticate_with_digest_authentiation()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 37 def authenticate_with_digest_authentiation return unless digest_enabled? realm = Calligraphy.http_authentication_realm authenticate_or_request_with_http_digest(realm) do |username| Calligraphy.digest_password_procedure.call(username) end end
client_nonce()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 88 def client_nonce auth_header = request.headers['HTTP_AUTHORIZATION'] digest = ::ActionController::HttpAuthentication::Digest auth = digest.decode_credentials auth_header auth[:cnonce] end
digest_enabled?()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 47 def digest_enabled? Calligraphy.enable_digest_authentication end
make_request(method)
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 70 def make_request(method) if method == 'head' status = get head: true elsif Calligraphy.allowed_http_methods.include? method resource_client_nonce(method) if digest_enabled? status, body = send method else status = :method_not_allowed end [status, body] end
resource_client_nonce(_method)
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 84 def resource_client_nonce(_method) @resource.client_nonce = client_nonce end
resource_id()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 62 def resource_id if params[:format] [params[:resource], params[:format]].join '.' else params[:resource] end end
send_response(status:, body: nil)
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 96 def send_response(status:, body: nil) if body.nil? head status else render body: body, status: status end end
set_resource()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 51 def set_resource @resource_class = params[:resource_class] || Calligraphy::Resource @resource_root_path = params[:resource_root_path] @resource = @resource_class.new( resource: resource_id, req: request, root_dir: @resource_root_path ) end
verify_resource_scope()
click to toggle source
# File lib/calligraphy/rails/web_dav_requests_controller.rb, line 30 def verify_resource_scope # Prevent any request with `.` or `..` as part of the resource. head :forbidden if %w[. ..].any? do |seg| params[:resource].include? seg end end