Module: Async::Caldav::Handlers::Get

Defined in:
lib/async/caldav/handlers/get.rb

Class Method Summary collapse

Class Method Details

.call(path:, storage:, headers: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/async/caldav/handlers/get.rb', line 13

def call(path:, storage:, headers: {}, **)
  item = storage.get_item(path.to_s)
  col_path = path.ensure_trailing_slash.to_s

  if item
    if headers['if-none-match'] == item[:etag]
      [304, { 'etag' => item[:etag], 'cache-control' => 'private, no-cache' }, []]
    else
      [200, { 'content-type' => item[:content_type], 'etag' => item[:etag], 'cache-control' => 'private, no-cache' }, [item[:body]]]
    end
  elsif storage.collection_exists?(col_path)
    items = storage.list_items(col_path)
    body = items.map { |_, data| data[:body] }.join("\n")
    [200, { 'content-type' => 'text/plain' }, [body]]
  elsif path.depth <= 2
    [200, { 'content-type' => 'text/html' }, ['<html><body>CalDAV</body></html>']]
  else
    [404, { 'content-type' => 'text/plain' }, ['Not Found']]
  end
end