Merge pull request #10637 from nupplaphil/feat/webdav_storage

PSR-7 Part 4: Add additional Authentication options
This commit is contained in:
Hypolite Petovan 2021-08-26 08:04:29 -04:00 committed by GitHub
commit a53cff6ec2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 11 deletions

View file

@ -125,6 +125,10 @@ class HTTPClient implements IHTTPClient
$conf[RequestOptions::BODY] = $opts[HTTPClientOptions::BODY]; $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) { $conf[RequestOptions::ON_HEADERS] = function (ResponseInterface $response) use ($opts) {
if (!empty($opts[HTTPClientOptions::CONTENT_LENGTH]) && if (!empty($opts[HTTPClientOptions::CONTENT_LENGTH]) &&
(int)$response->getHeaderLine('Content-Length') > $opts[HTTPClientOptions::CONTENT_LENGTH]) { (int)$response->getHeaderLine('Content-Length') > $opts[HTTPClientOptions::CONTENT_LENGTH]) {
@ -135,17 +139,7 @@ class HTTPClient implements IHTTPClient
try { try {
$this->logger->debug('http request config.', ['url' => $url, 'method' => $method, 'options' => $conf]); $this->logger->debug('http request config.', ['url' => $url, 'method' => $method, 'options' => $conf]);
switch ($method) { $response = $this->client->request($method, $url, $conf);
case 'get':
case 'head':
case 'post':
case 'put':
case 'delete':
$response = $this->client->$method($url, $conf);
break;
default:
throw new TransferException('Invalid method');
}
return new GuzzleResponse($response, $url); return new GuzzleResponse($response, $url);
} catch (TransferException $exception) { } catch (TransferException $exception) {
if ($exception instanceof RequestException && if ($exception instanceof RequestException &&

View file

@ -37,4 +37,8 @@ class HTTPClientOptions
* body: (mixed) Setting the body for sending data * body: (mixed) Setting the body for sending data
*/ */
const BODY = RequestOptions::BODY; const BODY = RequestOptions::BODY;
/**
* auth: (array) Authentication settings for specific requests
*/
const AUTH = RequestOptions::AUTH;
} }

View file

@ -97,6 +97,7 @@ interface IHTTPClient
* 'cookiejar' => path to cookie jar file * 'cookiejar' => path to cookie jar file
* 'header' => header array * 'header' => header array
* 'content_length' => int maximum File content length * 'content_length' => int maximum File content length
* 'auth' => array authentication settings
* *
* @return IHTTPResult * @return IHTTPResult
*/ */