From c99c7e1a97320a06852d22528931fd9ab58569c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jusi=C4=99ga?= Date: Sun, 12 Jan 2020 22:00:53 +0100 Subject: [PATCH 1/3] Add missing response content --- .../DataCollector/HttpClientDataCollector.php | 5 +++-- .../HttpClient/Tests/TraceableHttpClientTest.php | 4 +++- .../Component/HttpClient/TraceableHttpClient.php | 12 +++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php index 96bbe695b92ea..a23334a8e684c 100644 --- a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php +++ b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php @@ -131,8 +131,9 @@ private function collectOnClient(TraceableHttpClient $client): array } $debugInfo = array_diff_key($info, $baseInfo); - $info = array_diff_key($info, $debugInfo) + ['debug_info' => $debugInfo]; - unset($traces[$i]['info']); // break PHP reference used by TraceableHttpClient + $responseContent = $trace['response_content'] ?? null; + $info = array_diff_key($info, $debugInfo) + ['response_content' => $responseContent, 'debug_info' => $debugInfo]; + unset($traces[$i]['info'], $traces[$i]['response_content']); // break PHP reference used by TraceableHttpClient $traces[$i]['info'] = $this->cloneVar($info); $traces[$i]['options'] = $this->cloneVar($trace['options']); } diff --git a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php index 949d8afcff85a..10d5b8ad8ad7e 100755 --- a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php @@ -36,7 +36,7 @@ public function testItTracesRequest() return true; }) ) - ->willReturn(MockResponse::fromRequest('GET', '/foo/bar', ['options1' => 'foo'], new MockResponse())) + ->willReturn(MockResponse::fromRequest('GET', '/foo/bar', ['options1' => 'foo'], new MockResponse('{"foo": "bar"}'))) ; $sut = new TraceableHttpClient($httpClient); $sut->request('GET', '/foo/bar', ['options1' => 'foo']); @@ -47,6 +47,7 @@ public function testItTracesRequest() 'url' => '/foo/bar', 'options' => ['options1' => 'foo'], 'info' => [], + 'response_content' => ['foo' => 'bar'] ], $actualTracedRequest); } @@ -58,6 +59,7 @@ public function testItCollectsInfoOnRealRequest() $actualTracedRequest = $tracedRequests[0]; $this->assertSame('GET', $actualTracedRequest['info']['http_method']); $this->assertSame('http://localhost:8057/', $actualTracedRequest['info']['url']); + $this->assertNull($actualTracedRequest['response_content']); } public function testItExecutesOnProgressOption() diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index d60d0849cd95e..ce925b2598b18 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -35,11 +35,13 @@ public function __construct(HttpClientInterface $client) public function request(string $method, string $url, array $options = []): ResponseInterface { $traceInfo = []; + $responseContent = null; $this->tracedRequests[] = [ 'method' => $method, 'url' => $url, 'options' => $options, 'info' => &$traceInfo, + 'response_content' => &$responseContent ]; $onProgress = $options['on_progress'] ?? null; @@ -51,7 +53,15 @@ public function request(string $method, string $url, array $options = []): Respo } }; - return $this->client->request($method, $url, $options); + $response = $this->client->request($method, $url, $options); + + // Try to convert response to array if possible + try { + $responseContent = $response->toArray(false); + } catch (\Throwable $e) { + } + + return $response; } /** From da4be2ab2c346d3a79153efac58aa8fed09eedb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jusi=C4=99ga?= Date: Sun, 12 Jan 2020 22:18:19 +0100 Subject: [PATCH 2/3] change operator to isset --- .../HttpClient/DataCollector/HttpClientDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php index a23334a8e684c..903da4911b0a0 100644 --- a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php +++ b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php @@ -131,7 +131,7 @@ private function collectOnClient(TraceableHttpClient $client): array } $debugInfo = array_diff_key($info, $baseInfo); - $responseContent = $trace['response_content'] ?? null; + $responseContent = isset($trace['response_content']) ? $trace['response_content'] : null; $info = array_diff_key($info, $debugInfo) + ['response_content' => $responseContent, 'debug_info' => $debugInfo]; unset($traces[$i]['info'], $traces[$i]['response_content']); // break PHP reference used by TraceableHttpClient $traces[$i]['info'] = $this->cloneVar($info); From b91832e219c9d328e748f058d35e6e68f7f28938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jusi=C4=99ga?= Date: Sun, 12 Jan 2020 22:28:06 +0100 Subject: [PATCH 3/3] add missing commas --- .../Component/HttpClient/Tests/TraceableHttpClientTest.php | 2 +- src/Symfony/Component/HttpClient/TraceableHttpClient.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php index 10d5b8ad8ad7e..39b983cc16790 100755 --- a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php @@ -47,7 +47,7 @@ public function testItTracesRequest() 'url' => '/foo/bar', 'options' => ['options1' => 'foo'], 'info' => [], - 'response_content' => ['foo' => 'bar'] + 'response_content' => ['foo' => 'bar'], ], $actualTracedRequest); } diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index ce925b2598b18..e9dd7a8a4a7ff 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -41,7 +41,7 @@ public function request(string $method, string $url, array $options = []): Respo 'url' => $url, 'options' => $options, 'info' => &$traceInfo, - 'response_content' => &$responseContent + 'response_content' => &$responseContent, ]; $onProgress = $options['on_progress'] ?? null; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy