@@ 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 |
@@ 44-55 (lines=12) @@ | ||
41 | * @param array $options |
|
42 | * @return CancellablePromiseInterface |
|
43 | */ |
|
44 | public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface |
|
45 | { |
|
46 | if (!($request->getBody() instanceof JsonStream)) { |
|
47 | return resolve($request); |
|
48 | } |
|
49 | ||
50 | return $this->jsonEncodeService->handle($request->getBody()->getJson())->then(function ($json) use ($request) { |
|
51 | $body = new BufferStream(strlen($json)); |
|
52 | $body->write($json); |
|
53 | return resolve($request->withBody($body)); |
|
54 | }); |
|
55 | } |
|
56 | } |
|
57 |