Class: Async::Caldav::Server
- Inherits:
-
Object
- Object
- Async::Caldav::Server
- Defined in:
- lib/async/caldav/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(storage:) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(storage:) ⇒ Server
Returns a new instance of Server.
11 12 13 |
# File 'lib/async/caldav/server.rb', line 11 def initialize(storage:) @storage = storage end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/async/caldav/server.rb', line 15 def call(env) method = env['REQUEST_METHOD'] raw_path = env['PATH_INFO'] || '/' path = Protocol::Caldav::Path.new(raw_path, storage_class: @storage) # OPTIONS doesn't require auth return Handlers::Options.call(path: path, storage: @storage) if method == 'OPTIONS' # Auth check user = env['dav.user'] unless user && !user.to_s.empty? return [401, { 'content-type' => 'text/plain', 'www-authenticate' => 'Basic realm="caldav"' }, ['Unauthorized']] end # Path sanitization if raw_path.include?('..') return [400, { 'content-type' => 'text/plain' }, ['Bad Request']] end resource_type = resource_type_for(path) body = read_body(env) headers = extract_headers(env) dispatch(method, path: path, body: body, storage: @storage, user: user, headers: headers, resource_type: resource_type) end |