From 458e3fadd250b8f81954359cbb8d207cb9e4ae3e Mon Sep 17 00:00:00 2001 From: Cyril Chapellier Date: Tue, 21 Nov 2023 13:08:06 +0100 Subject: [PATCH] Fix OPTIONS call (#124) --- src/Controller/DAVController.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/DAVController.php b/src/Controller/DAVController.php index 8f7e797..ddcf840 100644 --- a/src/Controller/DAVController.php +++ b/src/Controller/DAVController.php @@ -295,8 +295,26 @@ private function initExceptionListener() */ public function dav(Request $request, string $path) { + // We need to acknowledge the OPTIONS call before sabre/dav for public + // calendars since we're circumventing the lib if ('OPTIONS' === $request->getMethod()) { - return new Response(); + $response = new Response(); + + // Adapted from CorePlugin's httpOptions() + // https://github.com/sabre-io/dav/blob/master/lib/DAV/CorePlugin.php#L210 + $methods = $this->server->getAllowedMethods(""); + + $response->headers->set('Allow', strtoupper(implode(', ', $methods))); + $features = ['1', '3', 'extended-mkcol']; + + foreach ($this->server->getPlugins() as $plugin) { + $features = array_merge($features, $plugin->getFeatures()); + } + + $response->headers->set('DAV', implode(', ', $features)); + $response->headers->set('MS-Author-Via', 'DAV'); + + return $response; } // \Sabre\DAV\Server does not let us use a custom SAPI, and its behaviour