| @@ 28-40 (lines=13) @@ | ||
| 25 | $this->client = $client; |
|
| 26 | } |
|
| 27 | ||
| 28 | public function handle(RequestCommandInterface $command): PromiseInterface |
|
| 29 | { |
|
| 30 | return $this->client->request( |
|
| 31 | $command->getRequest(), |
|
| 32 | $command->getOptions() |
|
| 33 | )->then(function (ResponseInterface $response) { |
|
| 34 | return BufferedSink::createPromise($response->getBody())->then(function (string $body) use ($response) { |
|
| 35 | $stream = new BufferStream(strlen($body)); |
|
| 36 | $stream->write($body); |
|
| 37 | return resolve($response->withBody($stream)); |
|
| 38 | }); |
|
| 39 | }); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| @@ 36-47 (lines=12) @@ | ||
| 33 | * @param array $options |
|
| 34 | * @return CancellablePromiseInterface |
|
| 35 | */ |
|
| 36 | public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface |
|
| 37 | { |
|
| 38 | if (!($request->getBody() instanceof JsonStream)) { |
|
| 39 | return resolve($request); |
|
| 40 | } |
|
| 41 | ||
| 42 | return $this->jsonEncodeService->handle($request->getBody()->getJson())->then(function ($json) use ($request) { |
|
| 43 | $body = new BufferStream(strlen($json)); |
|
| 44 | $body->write($json); |
|
| 45 | return resolve($request->withBody($body)); |
|
| 46 | }); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||