Skip to content

Commit 71632c1

Browse files
Merge branch '6.4' into 7.1
* 6.4: [HttpClient] Fix processing a NativeResponse after its client has been reset [Security] Throw an explicit error when authenticating a token with a null user translation to hebrew
2 parents 68a3501 + 394b440 commit 71632c1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Response/NativeResponse.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
};
8080

8181
$this->canary = new Canary(static function () use ($multi, $id) {
82-
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && 0 >= --$multi->hosts[$host]) {
82+
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
8383
unset($multi->hosts[$host]);
8484
}
8585
unset($multi->openHandles[$id], $multi->handlesActivity[$id]);
@@ -123,7 +123,7 @@ private function open(): void
123123
throw new TransportException($msg);
124124
}
125125

126-
$this->logger?->info(sprintf('%s for "%s".', $msg, $url ?? $this->url));
126+
$this->logger?->info(\sprintf('%s for "%s".', $msg, $url ?? $this->url));
127127
});
128128

129129
try {
@@ -142,7 +142,7 @@ private function open(): void
142142
$this->info['request_header'] = $this->info['url']['path'].$this->info['url']['query'];
143143
}
144144

145-
$this->info['request_header'] = sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
145+
$this->info['request_header'] = \sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
146146
$this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";
147147

148148
if (\array_key_exists('peer_name', $context['ssl']) && null === $context['ssl']['peer_name']) {
@@ -159,7 +159,7 @@ private function open(): void
159159
break;
160160
}
161161

162-
$this->logger?->info(sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
162+
$this->logger?->info(\sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
163163
}
164164
} catch (\Throwable $e) {
165165
$this->close();
@@ -294,15 +294,15 @@ private static function perform(ClientState $multi, ?array &$responses = null):
294294

295295
if (null === $e) {
296296
if (0 < $remaining) {
297-
$e = new TransportException(sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
297+
$e = new TransportException(\sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
298298
} elseif (-1 === $remaining && fwrite($buffer, '-') && '' !== stream_get_contents($buffer, -1, 0)) {
299299
$e = new TransportException('Transfer closed with outstanding data remaining from chunked response.');
300300
}
301301
}
302302

303303
$multi->handlesActivity[$i][] = null;
304304
$multi->handlesActivity[$i][] = $e;
305-
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && 0 >= --$multi->hosts[$host]) {
305+
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
306306
unset($multi->hosts[$host]);
307307
}
308308
unset($multi->openHandles[$i]);

Tests/HttpClientTestCase.php

+13
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,17 @@ public function testPostToGetRedirect(int $status)
700700
$this->assertSame('GET', $body['REQUEST_METHOD']);
701701
$this->assertSame('/', $body['REQUEST_URI']);
702702
}
703+
704+
public function testResponseCanBeProcessedAfterClientReset()
705+
{
706+
$client = $this->getHttpClient(__FUNCTION__);
707+
$response = $client->request('GET', 'http://127.0.0.1:8057/timeout-body');
708+
$stream = $client->stream($response);
709+
710+
$response->getStatusCode();
711+
$client->reset();
712+
$stream->current();
713+
714+
$this->addToAssertionCount(1);
715+
}
703716
}

0 commit comments

Comments
 (0)