From 1c089e8d89c5101592d4220ca2b861751c7d142d Mon Sep 17 00:00:00 2001
From: Philipp <admin@philipp.info>
Date: Wed, 25 Aug 2021 23:47:18 +0200
Subject: [PATCH] [WIP] WebDav Storage backend

---
 src/Network/HTTPClient.php        | 16 +++++-----------
 src/Network/HTTPClientOptions.php |  4 ++++
 src/Network/IHTTPClient.php       |  1 +
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/Network/HTTPClient.php b/src/Network/HTTPClient.php
index d265411c2c..053c65c0d1 100644
--- a/src/Network/HTTPClient.php
+++ b/src/Network/HTTPClient.php
@@ -125,6 +125,10 @@ class HTTPClient implements IHTTPClient
 			$conf[RequestOptions::BODY] = $opts[HTTPClientOptions::BODY];
 		}
 
+		if (!empty($opts[HTTPClientOptions::AUTH])) {
+			$conf[RequestOptions::AUTH] = $opts[HTTPClientOptions::AUTH];
+		}
+
 		$conf[RequestOptions::ON_HEADERS] = function (ResponseInterface $response) use ($opts) {
 			if (!empty($opts[HTTPClientOptions::CONTENT_LENGTH]) &&
 				(int)$response->getHeaderLine('Content-Length') > $opts[HTTPClientOptions::CONTENT_LENGTH]) {
@@ -135,17 +139,7 @@ class HTTPClient implements IHTTPClient
 		try {
 			$this->logger->debug('http request config.', ['url' => $url, 'method' => $method, 'options' => $conf]);
 
-			switch ($method) {
-				case 'get':
-				case 'head':
-				case 'post':
-				case 'put':
-				case 'delete':
-					$response = $this->client->$method($url, $conf);
-					break;
-				default:
-					throw new TransferException('Invalid method');
-			}
+			$response = $this->client->request($method, $url, $conf);
 			return new GuzzleResponse($response, $url);
 		} catch (TransferException $exception) {
 			if ($exception instanceof RequestException &&
diff --git a/src/Network/HTTPClientOptions.php b/src/Network/HTTPClientOptions.php
index f199360362..f9438fb479 100644
--- a/src/Network/HTTPClientOptions.php
+++ b/src/Network/HTTPClientOptions.php
@@ -37,4 +37,8 @@ class HTTPClientOptions
 	 * body: (mixed) Setting the body for sending data
 	 */
 	const BODY = RequestOptions::BODY;
+	/**
+	 * auth: (array) Authentication settings for specific requests
+	 */
+	const AUTH = RequestOptions::AUTH;
 }
diff --git a/src/Network/IHTTPClient.php b/src/Network/IHTTPClient.php
index 2f8bab46fc..8716805532 100644
--- a/src/Network/IHTTPClient.php
+++ b/src/Network/IHTTPClient.php
@@ -97,6 +97,7 @@ interface IHTTPClient
 	 *                           'cookiejar' => path to cookie jar file
 	 *                           'header' => header array
 	 *                           'content_length' => int maximum File content length
+	 *                           'auth' => array authentication settings
 	 *
 	 * @return IHTTPResult
 	 */
-- 
2.39.5