Skip to content

Commit

Permalink
chore: update fetch method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
christyjacob4 committed Mar 18, 2024
1 parent cf99dee commit 2f7f77e
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,54 @@ class Client

private array $headers = [];

Check failure on line 26 in src/Client.php

View workflow job for this annotation

GitHub Actions / CodeQL

Property Utopia\Fetch\Client::$headers type has no value type specified in iterable type array.
private array $curlOptions = [];

Check failure on line 27 in src/Client.php

View workflow job for this annotation

GitHub Actions / CodeQL

Property Utopia\Fetch\Client::$curlOptions type has no value type specified in iterable type array.
private int $timeout = 15;

Check failure on line 28 in src/Client.php

View workflow job for this annotation

GitHub Actions / CodeQL

Property Utopia\Fetch\Client::$timeout is never read, only written.
private int $connectTimeout = 60;

Check failure on line 29 in src/Client.php

View workflow job for this annotation

GitHub Actions / CodeQL

Property Utopia\Fetch\Client::$connectTimeout is never read, only written.
private int $maxRedirects = 5;

Check failure on line 30 in src/Client.php

View workflow job for this annotation

GitHub Actions / CodeQL

Property Utopia\Fetch\Client::$maxRedirects is never read, only written.

/**
* @param string $key
* @param string $value
* @return self
*/
public function addHeader(string $key, string $value): self
{
$this->headers[$key] = $value;
return $this;
}

/**
* Set the request timeout.
*
* @param int $timeout
* @return self
*/
public function setTimeout(int $timeout): self
{
$this->timeout = $timeout;
return $this;
}

/**
* @param array<string, string> $headers
* Set the maximum number of redirects.
*
* @param int $maxRedirects
* @return self
*/
public function setHeaders(array $headers): self
public function setMaxRedirects(int $maxRedirects): self
{
$this->headers = $headers;
$this->curlOptions[CURLOPT_MAXREDIRS] = $maxRedirects;
return $this;
}

/**
* @param array $curlOptions
* Set the connection timeout.
*
* @param int $connectTimeout
* @return self
*/
public function setCurlOptions(array $curlOptions): self
public function setConnectTimeout(int $connectTimeout): self
{
$this->curlOptions = $curlOptions;
$this->connectTimeout = $connectTimeout;
return $this;
}

Expand Down Expand Up @@ -118,7 +147,13 @@ public function fetch(
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HEADERFUNCTION => function ($curl, $header) use (&$responseHeaders) {
// Header processing remains unchanged...
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) { // ignore invalid headers
return $len;
}
$responseHeaders[strtolower(trim($header[0]))] = trim($header[1]);
return $len;
},
CURLOPT_CONNECTTIMEOUT => 60,
CURLOPT_TIMEOUT => 15,
Expand Down

0 comments on commit 2f7f77e

Please sign in to comment.