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:
parent
6bf422c0f1
commit
fc28032748
|
@ -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;
|
||||
|
|
|
@ -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('');
|
||||
|
|
|
@ -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')]
|
||||
|
|
Loading…
Reference in New Issue