handle empty encoded responses (#1337)

at least one otel backend product sends an empty response with a gzip encoding, which we fail to decode (because
an empty string is not valid). Work around this by not trying to decode an empty value.
This commit is contained in:
Brett McBride 2024-06-20 09:44:40 +10:00 committed by GitHub
parent 6bf422c0f1
commit fc28032748
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View File

@ -91,6 +91,10 @@ final class PsrUtils
*/
public static function decode(string $value, array $encodings): string
{
if ($value === '') {
return $value;
}
for ($i = count($encodings); --$i >= 0;) {
if (strcasecmp($encodings[$i], 'identity') === 0) {
continue;

View File

@ -97,7 +97,7 @@ final class PsrTransportTest extends TestCase
public function test_send_decode_unknown_encoding_returns_error(): void
{
$this->client->expects($this->once())->method('sendRequest')->willReturn(new Response(200, ['Content-Encoding' => 'invalid'], ''));
$this->client->expects($this->once())->method('sendRequest')->willReturn(new Response(200, ['Content-Encoding' => 'invalid'], 'foo'));
$transport = $this->factory->create('http://localhost', 'text/plain');
$response = $transport->send('');

View File

@ -89,7 +89,12 @@ final class PsrUtilsTest extends TestCase
{
$this->expectException(UnexpectedValueException::class);
PsrUtils::decode('', ['invalid']);
PsrUtils::decode('foo', ['invalid']);
}
public function test_decode_empty_value(): void
{
$this->assertSame('', PsrUtils::decode('', ['gzip']));
}
#[DataProvider('compressionProvider')]