diff --git a/CurlHttpClient.php b/CurlHttpClient.php index 9aff84d..96c37a5 100644 --- a/CurlHttpClient.php +++ b/CurlHttpClient.php @@ -301,7 +301,7 @@ public function request(string $method, string $url, array $options = []): Respo } } - return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number']); + return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number'], $url); } /** diff --git a/DataCollector/HttpClientDataCollector.php b/DataCollector/HttpClientDataCollector.php index dc4b676..7265bab 100644 --- a/DataCollector/HttpClientDataCollector.php +++ b/DataCollector/HttpClientDataCollector.php @@ -178,8 +178,7 @@ private function getCurlCommand(array $trace): ?string return null; } - $debug = explode("\n", $trace['info']['debug']); - $url = self::mergeQueryString($trace['url'], $trace['options']['query'] ?? [], true); + $url = $trace['info']['original_url'] ?? $trace['info']['url'] ?? $trace['url']; $command = ['curl', '--compressed']; if (isset($trace['options']['resolve'])) { @@ -194,12 +193,12 @@ private function getCurlCommand(array $trace): ?string $dataArg = []; if ($json = $trace['options']['json'] ?? null) { - $dataArg[] = '--data '.escapeshellarg(json_encode($json, \JSON_PRETTY_PRINT)); + $dataArg[] = '--data '.escapeshellarg(self::jsonEncode($json)); } elseif ($body = $trace['options']['body'] ?? null) { if (\is_string($body)) { try { $dataArg[] = '--data '.escapeshellarg($body); - } catch (\ValueError $e) { + } catch (\ValueError) { return null; } } elseif (\is_array($body)) { @@ -214,7 +213,7 @@ private function getCurlCommand(array $trace): ?string $dataArg = empty($dataArg) ? null : implode(' ', $dataArg); - foreach ($debug as $line) { + foreach (explode("\n", $trace['info']['debug']) as $line) { $line = substr($line, 0, -1); if (str_starts_with('< ', $line)) { diff --git a/Response/AmpResponse.php b/Response/AmpResponse.php index f5d0095..f107ccf 100644 --- a/Response/AmpResponse.php +++ b/Response/AmpResponse.php @@ -80,6 +80,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti $info['http_method'] = $request->getMethod(); $info['start_time'] = null; $info['redirect_url'] = null; + $info['original_url'] = $info['url']; $info['redirect_time'] = 0.0; $info['redirect_count'] = 0; $info['size_upload'] = 0.0; diff --git a/Response/CurlResponse.php b/Response/CurlResponse.php index 9a8abca..233198f 100644 --- a/Response/CurlResponse.php +++ b/Response/CurlResponse.php @@ -43,7 +43,7 @@ final class CurlResponse implements ResponseInterface, StreamableInterface /** * @internal */ - public function __construct(CurlClientState $multi, \CurlHandle|string $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null) + public function __construct(CurlClientState $multi, \CurlHandle|string $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null, string $originalUrl = null) { $this->multi = $multi; @@ -69,6 +69,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra $this->info['user_data'] = $options['user_data'] ?? null; $this->info['max_duration'] = $options['max_duration'] ?? null; $this->info['start_time'] = $this->info['start_time'] ?? microtime(true); + $this->info['original_url'] = $originalUrl ?? $this->info['url'] ?? curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL); $info = &$this->info; $headers = &$this->headers; $debugBuffer = $this->debugBuffer; diff --git a/Response/MockResponse.php b/Response/MockResponse.php index fe89cd1..044734a 100644 --- a/Response/MockResponse.php +++ b/Response/MockResponse.php @@ -142,6 +142,7 @@ public static function fromRequest(string $method, string $url, array $options, $response->info['user_data'] = $options['user_data'] ?? null; $response->info['max_duration'] = $options['max_duration'] ?? null; $response->info['url'] = $url; + $response->info['original_url'] = $url; if ($mock instanceof self) { $mock->requestOptions = $response->requestOptions; diff --git a/Response/NativeResponse.php b/Response/NativeResponse.php index 077d8f9..ab0cf09 100644 --- a/Response/NativeResponse.php +++ b/Response/NativeResponse.php @@ -66,6 +66,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr // Temporary resource to dechunk the response stream $this->buffer = fopen('php://temp', 'w+'); + $info['original_url'] = implode('', $info['url']); $info['user_data'] = $options['user_data']; $info['max_duration'] = $options['max_duration']; ++$multi->responseCount; diff --git a/Tests/DataCollector/HttpClientDataCollectorTest.php b/Tests/DataCollector/HttpClientDataCollectorTest.php index 863c91d..18b0847 100755 --- a/Tests/DataCollector/HttpClientDataCollectorTest.php +++ b/Tests/DataCollector/HttpClientDataCollectorTest.php @@ -194,6 +194,22 @@ public function provideCurlRequests(): iterable --url %1$shttp://localhost:8057/json%1$s \\ --header %1$sAccept: */*%1$s \\ --header %1$sAccept-Encoding: gzip%1$s \\ + --header %1$sUser-Agent: Symfony HttpClient/Native%1$s', + ]; + yield 'GET with base uri' => [ + [ + 'method' => 'GET', + 'url' => '1', + 'options' => [ + 'base_uri' => 'http://localhost:8057/json/', + ], + ], + 'curl \\ + --compressed \\ + --request GET \\ + --url %1$shttp://localhost:8057/json/1%1$s \\ + --header %1$sAccept: */*%1$s \\ + --header %1$sAccept-Encoding: gzip%1$s \\ --header %1$sUser-Agent: Symfony HttpClient/Native%1$s', ]; yield 'GET with resolve' => [ @@ -307,6 +323,8 @@ public function __toString(): string 'json' => [ 'foo' => [ 'bar' => 'baz', + 'qux' => [1.10, 1.0], + 'fred' => ['',"'bar'",'"baz"','&blong&'], ], ], ], @@ -317,14 +335,10 @@ public function __toString(): string --url %1$shttp://localhost:8057/json%1$s \\ --header %1$sContent-Type: application/json%1$s \\ --header %1$sAccept: */*%1$s \\ - --header %1$sContent-Length: 21%1$s \\ + --header %1$sContent-Length: 120%1$s \\ --header %1$sAccept-Encoding: gzip%1$s \\ --header %1$sUser-Agent: Symfony HttpClient/Native%1$s \\ - --data %1$s{ - "foo": { - "bar": "baz" - } -}%1$s', + --data %1$s{"foo":{"bar":"baz","qux":[1.1,1.0],"fred":["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026"]}}%1$s', ]; } } 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