Skip to content

Commit 2341c4b

Browse files
Merge branch '4.4' into 5.4
* 4.4: [HttpClient] always send Content-Type when a body is passed
2 parents 3f35854 + b83d683 commit 2341c4b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

AmpHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function request(string $method, string $url, array $options = []): Respo
9292
}
9393
}
9494

95-
if (('' !== $options['body'] || 'POST' === $method) && !isset($options['normalized_headers']['content-type'])) {
95+
if (('' !== $options['body'] || 'POST' === $method || isset($options['normalized_headers']['content-length'])) && !isset($options['normalized_headers']['content-type'])) {
9696
$options['headers'][] = 'Content-Type: application/x-www-form-urlencoded';
9797
}
9898

CurlHttpClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ public function request(string $method, string $url, array $options = []): Respo
245245

246246
if ('POST' !== $method) {
247247
$curlopts[\CURLOPT_UPLOAD] = true;
248+
249+
if (!isset($options['normalized_headers']['content-type'])) {
250+
$curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
251+
}
248252
}
249253
} elseif ('' !== $body || 'POST' === $method || $hasContentLength) {
250254
$curlopts[\CURLOPT_POSTFIELDS] = $body;
251-
252-
if ('' === $body && 'POST' !== $method && !isset($options['normalized_headers']['content-type'])) {
253-
$curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type:';
254-
}
255255
}
256256

257257
if ($options['peer_fingerprint']) {

NativeHttpClient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ public function request(string $method, string $url, array $options = []): Respo
8181
}
8282
}
8383

84-
$sendContentLength = !\is_string($options['body']) || 'POST' === $method;
84+
$hasContentLength = isset($options['normalized_headers']['content-length']);
85+
$hasBody = '' !== $options['body'] || 'POST' === $method || $hasContentLength;
8586

8687
$options['body'] = self::getBodyAsString($options['body']);
8788

88-
if ('' === $options['body'] && $sendContentLength && !isset($options['normalized_headers']['content-length'])) {
89+
if ('' === $options['body'] && $hasBody && !$hasContentLength) {
8990
$options['headers'][] = 'Content-Length: 0';
9091
}
91-
if (('' !== $options['body'] || 'POST' === $method) && !isset($options['normalized_headers']['content-type'])) {
92+
if ($hasBody && !isset($options['normalized_headers']['content-type'])) {
9293
$options['headers'][] = 'Content-Type: application/x-www-form-urlencoded';
9394
}
9495

0 commit comments

Comments
 (0)