Skip to content

Commit

Permalink
Apply Sabre Workaround also after authenticated request attempt (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Mar 6, 2024
1 parent c368baf commit e7bd1b8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/HttpClientAdapterGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e7bd1b8

Please sign in to comment.