Skip to content

Commit

Permalink
Fixed WebDAV request options
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Aug 7, 2017
1 parent aeaae5e commit 7053af6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Jyxo/Webdav/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ class Client
* @var array
*/
protected $requestOptions = [
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false,
\GuzzleHttp\RequestOptions::DECODE_CONTENT => true,
\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 1,
\GuzzleHttp\RequestOptions::TIMEOUT => 30
\GuzzleHttp\RequestOptions::TIMEOUT => 30,
\GuzzleHttp\RequestOptions::VERIFY => true
];

/**
Expand Down Expand Up @@ -123,7 +126,7 @@ public function __construct(array $servers)
}

/**
* Sets a request option.
* Sets a request option for Guzzle client.
*
* @param string $name Option name
* @param mixed $value Option value
Expand Down Expand Up @@ -533,7 +536,7 @@ protected function sendAllRequests(array $requests): array
// Create promises
$promises = [];
foreach ($requests as $server => $request) {
$promises[$server] = $client->sendAsync($request, $this->requestOptions);
$promises[$server] = $client->sendAsync($request, $this->getStaticRequestOptions());
}

// Wait on all of the requests to complete
Expand All @@ -553,7 +556,7 @@ protected function sendAllRequests(array $requests): array

// Send by separate requests
foreach ($requests as $server => $request) {
$response = $client->send($request, $this->requestOptions);
$response = $client->send($request, $this->getStaticRequestOptions());
$responses[$server] = $response;

// Log
Expand Down Expand Up @@ -583,7 +586,7 @@ protected function sendRequest(string $path, string $method, array $headers = []
try {
// Send request to a random server
$request = $this->createRequest($this->getRandomServer(), $path, $method, $headers);
$response = $this->createClient()->send($request, $this->requestOptions);
$response = $this->createClient()->send($request, $this->getStaticRequestOptions());

if (null !== $this->logger) {
$this->logger->log(sprintf("%s %d %s", $request->getMethod(), $response->getStatusCode(), $request->getUri()));
Expand Down Expand Up @@ -633,18 +636,20 @@ protected function createRequest(string $server, string $path, string $method, a
);
}

private function getStaticRequestOptions(): array
{
return [
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false,
\GuzzleHttp\RequestOptions::EXPECT => false,
];
}

/**
* @return \GuzzleHttp\Client
*/
protected function createClient(): \GuzzleHttp\Client
{
return new \GuzzleHttp\Client([
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false,
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false,
\GuzzleHttp\RequestOptions::VERIFY => true,
\GuzzleHttp\RequestOptions::DECODE_CONTENT => true,
\GuzzleHttp\RequestOptions::EXPECT => false,
]);
return new \GuzzleHttp\Client($this->requestOptions);
}

/**
Expand Down

0 comments on commit 7053af6

Please sign in to comment.