Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b44dc6

Browse filesBrowse files
bug #46665 [HttpClient] Fix Copy as curl with base uri (HypeMC)
This PR was merged into the 6.1 branch. Discussion ---------- [HttpClient] Fix Copy as curl with base uri | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46583 (comment) | License | MIT | Doc PR | - Fixes Copy as curl when `base_uri` is used. Commits ------- 12e40a0 [HttpClient] Fix Copy as curl with base uri
2 parents b78725a + 12e40a0 commit 6b44dc6
Copy full SHA for 6b44dc6

File tree

7 files changed

+25
-6
lines changed
Filter options

7 files changed

+25
-6
lines changed

‎src/Symfony/Component/HttpClient/CurlHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function request(string $method, string $url, array $options = []): Respo
301301
}
302302
}
303303

304-
return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number']);
304+
return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number'], $url);
305305
}
306306

307307
/**

‎src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ private function getCurlCommand(array $trace): ?string
178178
return null;
179179
}
180180

181-
$debug = explode("\n", $trace['info']['debug']);
182-
$url = self::mergeQueryString($trace['url'], $trace['options']['query'] ?? [], true);
181+
$url = $trace['info']['original_url'] ?? $trace['info']['url'] ?? $trace['url'];
183182
$command = ['curl', '--compressed'];
184183

185184
if (isset($trace['options']['resolve'])) {
@@ -199,7 +198,7 @@ private function getCurlCommand(array $trace): ?string
199198
if (\is_string($body)) {
200199
try {
201200
$dataArg[] = '--data '.escapeshellarg($body);
202-
} catch (\ValueError $e) {
201+
} catch (\ValueError) {
203202
return null;
204203
}
205204
} elseif (\is_array($body)) {
@@ -214,7 +213,7 @@ private function getCurlCommand(array $trace): ?string
214213

215214
$dataArg = empty($dataArg) ? null : implode(' ', $dataArg);
216215

217-
foreach ($debug as $line) {
216+
foreach (explode("\n", $trace['info']['debug']) as $line) {
218217
$line = substr($line, 0, -1);
219218

220219
if (str_starts_with('< ', $line)) {

‎src/Symfony/Component/HttpClient/Response/AmpResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/AmpResponse.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti
8080
$info['http_method'] = $request->getMethod();
8181
$info['start_time'] = null;
8282
$info['redirect_url'] = null;
83+
$info['original_url'] = $info['url'];
8384
$info['redirect_time'] = 0.0;
8485
$info['redirect_count'] = 0;
8586
$info['size_upload'] = 0.0;

‎src/Symfony/Component/HttpClient/Response/CurlResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/CurlResponse.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class CurlResponse implements ResponseInterface, StreamableInterface
4343
/**
4444
* @internal
4545
*/
46-
public function __construct(CurlClientState $multi, \CurlHandle|string $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null)
46+
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)
4747
{
4848
$this->multi = $multi;
4949

@@ -69,6 +69,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra
6969
$this->info['user_data'] = $options['user_data'] ?? null;
7070
$this->info['max_duration'] = $options['max_duration'] ?? null;
7171
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
72+
$this->info['original_url'] = $originalUrl ?? $this->info['url'] ?? curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL);
7273
$info = &$this->info;
7374
$headers = &$this->headers;
7475
$debugBuffer = $this->debugBuffer;

‎src/Symfony/Component/HttpClient/Response/MockResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/MockResponse.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static function fromRequest(string $method, string $url, array $options,
142142
$response->info['user_data'] = $options['user_data'] ?? null;
143143
$response->info['max_duration'] = $options['max_duration'] ?? null;
144144
$response->info['url'] = $url;
145+
$response->info['original_url'] = $url;
145146

146147
if ($mock instanceof self) {
147148
$mock->requestOptions = $response->requestOptions;

‎src/Symfony/Component/HttpClient/Response/NativeResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/NativeResponse.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr
6666
// Temporary resource to dechunk the response stream
6767
$this->buffer = fopen('php://temp', 'w+');
6868

69+
$info['original_url'] = implode('', $info['url']);
6970
$info['user_data'] = $options['user_data'];
7071
$info['max_duration'] = $options['max_duration'];
7172
++$multi->responseCount;

‎src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ public function provideCurlRequests(): iterable
194194
--url %1$shttp://localhost:8057/json%1$s \\
195195
--header %1$sAccept: */*%1$s \\
196196
--header %1$sAccept-Encoding: gzip%1$s \\
197+
--header %1$sUser-Agent: Symfony HttpClient/Native%1$s',
198+
];
199+
yield 'GET with base uri' => [
200+
[
201+
'method' => 'GET',
202+
'url' => '1',
203+
'options' => [
204+
'base_uri' => 'http://localhost:8057/json/',
205+
],
206+
],
207+
'curl \\
208+
--compressed \\
209+
--request GET \\
210+
--url %1$shttp://localhost:8057/json/1%1$s \\
211+
--header %1$sAccept: */*%1$s \\
212+
--header %1$sAccept-Encoding: gzip%1$s \\
197213
--header %1$sUser-Agent: Symfony HttpClient/Native%1$s',
198214
];
199215
yield 'GET with resolve' => [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.