Skip to content

Commit

Permalink
Merge branch '5.3' into 5.4
Browse files Browse the repository at this point in the history
* 5.3:
  [5.3] cs fixes
  [Cache] Fix saving items with no expiration through ProxyAdapter
  CS fixes
  [HttpClient] Fix tracing requests made after calling withOptions()
  [Cache] disable lock on CLI
  [VarDumper] add more "transient-on-macos" groups
  • Loading branch information
nicolas-grekas committed Dec 16, 2021
2 parents c1fcbee + 5c141de commit d6c0e0e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
$curlVersion = $curlVersion ?? curl_version();

// HTTP/2 push crashes before curl 7.61
if (0x073d00 > $curlVersion['version_number'] || !(\CURL_VERSION_HTTP2 & $curlVersion['features'])) {
if (0x073D00 > $curlVersion['version_number'] || !(\CURL_VERSION_HTTP2 & $curlVersion['features'])) {
return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Response/AmpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private static function followRedirects(Request $originRequest, AmpClientState $
// Discard body of redirects
while (null !== yield $response->getBody()->read()) {
}
} catch (HttpException | StreamException $e) {
} catch (HttpException|StreamException $e) {
// Ignore streaming errors on previous responses
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/CurlHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
$this->markTestSkipped('PHP 7.3.0 to 7.3.3 don\'t support HTTP/2 PUSH');
}

if (!\defined('CURLMOPT_PUSHFUNCTION') || 0x073d00 > ($v = curl_version())['version_number'] || !(\CURL_VERSION_HTTP2 & $v['features'])) {
if (!\defined('CURLMOPT_PUSHFUNCTION') || 0x073D00 > ($v = curl_version())['version_number'] || !(\CURL_VERSION_HTTP2 & $v['features'])) {
$this->markTestSkipped('curl <7.61 is used or it is not compiled with support for HTTP/2 PUSH');
}
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/TraceableHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,18 @@ public function testStopwatchDestruct()
$this->assertCount(1, $events['GET http://localhost:8057']->getPeriods());
$this->assertGreaterThan(0.0, $events['GET http://localhost:8057']->getDuration());
}

public function testWithOptions()
{
$sut = new TraceableHttpClient(new NativeHttpClient());

$sut2 = $sut->withOptions(['base_uri' => 'http://localhost:8057']);

$response = $sut2->request('GET', '/');

$this->assertSame(200, $response->getStatusCode());
$this->assertSame('http://localhost:8057/', $response->getInfo('url'));

$this->assertCount(1, $sut->getTracedRequests());
}
}
7 changes: 4 additions & 3 deletions TraceableHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
final class TraceableHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface
{
private $client;
private $tracedRequests = [];
private $stopwatch;
private $tracedRequests;

public function __construct(HttpClientInterface $client, Stopwatch $stopwatch = null)
{
$this->client = $client;
$this->stopwatch = $stopwatch;
$this->tracedRequests = new \ArrayObject();
}

/**
Expand Down Expand Up @@ -84,7 +85,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa

public function getTracedRequests(): array
{
return $this->tracedRequests;
return $this->tracedRequests->getArrayCopy();
}

public function reset()
Expand All @@ -93,7 +94,7 @@ public function reset()
$this->client->reset();
}

$this->tracedRequests = [];
$this->tracedRequests->exchangeArray([]);
}

/**
Expand Down

0 comments on commit d6c0e0e

Please sign in to comment.