Skip to content

Commit 61d82d2

Browse files
CI runs \o/ (but still red)
1 parent 78e03c0 commit 61d82d2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Symfony/Component/HttpClient/Internal/AmpBody.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class AmpBody implements HttpContent, ReadableStream, \IteratorAggregate
2828
{
2929
private ReadableStream $body;
30+
private ?string $content;
3031
private array $info;
3132
private \Closure $onProgress;
3233
private ?int $offset = 0;
@@ -48,6 +49,7 @@ public function __construct($body, &$info, \Closure $onProgress)
4849
} elseif (\is_string($body)) {
4950
$this->length = \strlen($body);
5051
$this->body = new ReadableBuffer($body);
52+
$this->content = $body;
5153
} else {
5254
$this->body = new ReadableIterableStream((static function () use ($body) {
5355
while ('' !== $data = ($body)(16372)) {
@@ -134,14 +136,12 @@ public static function rewind(HttpContent $body): HttpContent
134136

135137
$body->uploaded = null;
136138

137-
if ($body->body instanceof ReadableResourceStream) {
139+
if ($body->body instanceof ReadableResourceStream && !$body->body->isClosed()) {
138140
fseek($body->body->getResource(), $body->offset);
139-
140-
return new $body($body->body->getResource(), $body->info, $body->onProgress);
141141
}
142142

143143
if ($body->body instanceof ReadableBuffer) {
144-
return new $body($body->body->read(), $body->info, $body->onProgress);
144+
return new $body($body->content, $body->info, $body->onProgress);
145145
}
146146

147147
return $body;

src/Symfony/Component/HttpClient/Response/AmpResponse.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti
106106

107107
$this->canary = new Canary(static function () use ($canceller, $multi, $id) {
108108
$canceller->cancel();
109+
$multi->openHandles[$id]?->isComplete() || $multi->openHandles[$id]->complete();
109110
unset($multi->openHandles[$id], $multi->handlesActivity[$id]);
110111
});
111112

@@ -132,7 +133,11 @@ public function __wakeup()
132133
public function __destruct()
133134
{
134135
try {
135-
$this->doDestruct();
136+
if ($this->initializer && null === $this->info['error']) {
137+
$clone = clone $this;
138+
$clone->shouldBuffer = true;
139+
EventLoop::queue($clone->getHeaders(...));
140+
}
136141
} finally {
137142
// Clear the DNS cache when all requests completed
138143
if (0 >= --$this->multi->responseCount) {
@@ -260,8 +265,6 @@ private static function generateResponse(Request $request, AmpClientState $multi
260265
} finally {
261266
$info['download_content_length'] = $info['size_download'];
262267
}
263-
264-
$multi->openHandles[$id]->complete();
265268
}
266269

267270
private static function followRedirects(Request $originRequest, AmpClientState $multi, array &$info, array &$headers, DeferredCancellation $canceller, array $options, \Closure $onProgress, &$handle, ?LoggerInterface $logger, float &$pause): ?Response

0 commit comments

Comments
 (0)