Skip to content

Commit 72a1d8d

Browse files
authored
Merge pull request #13 from reactphp-parallel/enforce-string-body-stream
Enforce stream request/response body stream
2 parents c65bafd + 1b45e7c commit 72a1d8d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ReactMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ReactParallel\Psr15Adapter;
66

7+
use Ancarda\Psr7\StringStream\ReadOnlyStringStream;
78
use parallel\Channel;
89
use Psr\Http\Message\ResponseInterface;
910
use Psr\Http\Message\ServerRequestInterface;
@@ -39,14 +40,16 @@ public function __construct(
3940

4041
public function __invoke(ServerRequestInterface $request, callable $next): PromiseInterface
4142
{
43+
$request = $request->withBody(new ReadOnlyStringStream((string) $request->getBody()));
44+
4245
return new Promise(function (callable $resolve, callable $reject) use ($request, $next): void {
4346
$input = new Channel(Channel::Infinite);
4447
$output = new Channel(Channel::Infinite);
4548

4649
$this->streamFactory->single($output)->then(static function (string $request): ServerRequestInterface {
4750
return unserialize($request);
4851
}, $reject)->then($next)->then(static function (ResponseInterface $response): string {
49-
return serialize($response);
52+
return serialize($response->withBody(new ReadOnlyStringStream((string) $response->getBody())));
5053
}, $reject)->then(static function (string $response) use ($input): void {
5154
$input->send($response);
5255
}, $reject);

0 commit comments

Comments
 (0)