Skip to content

Commit 354b2c0

Browse files
committed
fix: patch post arrays + headers parsing
1 parent 3f95b6f commit 354b2c0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Fetch.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,23 @@ private static function call($request)
260260
CURLOPT_RETURNTRANSFER => true,
261261
CURLOPT_FOLLOWLOCATION => true,
262262
CURLOPT_MAXREDIRS => $request["maxRedirects"],
263-
CURLOPT_HTTPHEADER => $request["headers"],
264263
CURLOPT_HEADER => true,
265264
CURLOPT_SSL_VERIFYPEER => $request["verifyPeer"],
266265
CURLOPT_SSL_VERIFYHOST => $request["verifyHost"] === false ? 0 : 2,
267266
// If an empty string, '', is set, a header containing all supported encoding types is sent
268267
CURLOPT_ENCODING => ""
269268
];
270269

270+
if (!empty($request["headers"])) {
271+
$formattedHeaders = [];
272+
273+
foreach ($request["headers"] as $key => $value) {
274+
$formattedHeaders[] = $key . ': ' . $value;
275+
}
276+
277+
$curl_base_options[CURLOPT_HTTPHEADER] = $formattedHeaders;
278+
}
279+
271280
if ($request["method"] !== static::GET) {
272281
if ($request["method"] === static::POST) {
273282
$curl_base_options[CURLOPT_POST] = true;
@@ -279,7 +288,7 @@ private static function call($request)
279288
$curl_base_options[CURLOPT_CUSTOMREQUEST] = $request["method"];
280289
}
281290

282-
$curl_base_options[CURLOPT_POSTFIELDS] = $request["data"];
291+
$curl_base_options[CURLOPT_POSTFIELDS] = json_encode($request["data"]);
283292
} else if (\is_array($request["data"])) {
284293
if (strpos($request["url"], '?') !== false) {
285294
$request["url"] .= '&';

0 commit comments

Comments
 (0)