From e7bd1b8f10bf840b3478d38d84b3cc82547615c6 Mon Sep 17 00:00:00 2001 From: Michael Stilkerich Date: Wed, 6 Mar 2024 17:02:24 +0100 Subject: [PATCH] Apply Sabre Workaround also after authenticated request attempt (#27) --- src/HttpClientAdapterGuzzle.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/HttpClientAdapterGuzzle.php b/src/HttpClientAdapterGuzzle.php index bebce8c..dcd77f8 100644 --- a/src/HttpClientAdapterGuzzle.php +++ b/src/HttpClientAdapterGuzzle.php @@ -167,8 +167,8 @@ public function sendRequest(string $method, string $uri, array $options = []): P $response = $this->client->request($method, $uri, $guzzleOptions); // Workaround for Sabre/DAV vs. Curl incompatibility + // (1) Sometimes, a REPORT is directly rejected without authentication attempt if ($doAuth && $this->checkSabreCurlIncompatibility($method, $response)) { - Config::$logger->debug("Attempting workaround for Sabre/Dav / curl incompatibility"); $guzzleOptions = $this->prepareGuzzleOptions($options, $doAuth); $response = $this->client->request($method, $uri, $guzzleOptions); } @@ -183,6 +183,13 @@ public function sendRequest(string $method, string $uri, array $options = []): P $response = $this->client->request($method, $uri, $guzzleOptions); if ($response->getStatusCode() != 401) { + // (2) Othertimes, a REPORT without authentication is first quitted with a 401, but the + // subsequent digest authentication attempt then gets the empty-body 500 reply + if ($this->checkSabreCurlIncompatibility($method, $response)) { + $guzzleOptions = $this->prepareGuzzleOptions($options, $doAuth); + $response = $this->client->request($method, $uri, $guzzleOptions); + } + break; } else { $this->failedAuthSchemes[] = $scheme; @@ -262,6 +269,7 @@ private function checkSabreCurlIncompatibility(string $method, Psr7Response $res ) { $body = (string) $response->getBody(); if (strpos($body, "The input element to parse is empty. Do not attempt to parse") !== false) { + Config::$logger->debug("Attempting workaround for Sabre/Dav / curl incompatibility"); $this->authScheme = "curlany"; return true; }