Skip to content

Commit

Permalink
Merge branch '6.0' into 6.1
Browse files Browse the repository at this point in the history
* 6.0:
  [HttpKernel] Fix empty request stack when terminating with exception
  [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger
  [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses
  [HttpClient] Fix buffering after calling AsyncContext::passthru()
  s/annd/and
  s/gargage/garbage
  [Console] Fix error output on windows cli
  Reserve keys when using numeric ones
  add missing Azerbaijani translations
  fix few typos/inconsistencies in latvian translations
  Fix TypeError in Router when using UrlGenerator
  [Messenger] Fix amqp socket lost
  fix: use message object from event
  • Loading branch information
nicolas-grekas committed Oct 18, 2022
2 parents 1798671 + 31797f9 commit fa931a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Response/AsyncContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,15 @@ public function replaceResponse(ResponseInterface $response): ResponseInterface

/**
* Replaces or removes the chunk filter iterator.
*
* @param ?callable(ChunkInterface, self): ?\Iterator $passthru
*/
public function passthru(callable $passthru = null): void
{
$this->passthru = $passthru;
$this->passthru = $passthru ?? static function ($chunk, $context) {
$context->passthru = null;

yield $chunk;
};
}
}
18 changes: 18 additions & 0 deletions Tests/RetryableHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,22 @@ public function log($level, $message, array $context = []): void
$this->assertNotNull($delay);
$this->assertSame((int) ($retryAfter * 1000), $delay);
}

public function testRetryOnErrorAssertContent()
{
$client = new RetryableHttpClient(
new MockHttpClient([
new MockResponse('', ['http_code' => 500]),
new MockResponse('Test out content', ['http_code' => 200]),
]),
new GenericRetryStrategy([500], 0),
1
);

$response = $client->request('GET', 'http://example.com/foo-bar');

self::assertSame(200, $response->getStatusCode());
self::assertSame('Test out content', $response->getContent());
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
}
}

0 comments on commit fa931a5

Please sign in to comment.