Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
no Database
What happened?
Hi, I found this behavior accidentally where once a request was sent using "json" parameters, the next curl request will have it's "body" parameters overriden by the previous request configuration.
This might relate to CURLRequest.php line 638 or
parseOptions methods on CURLRequest.php.
Here's a snippet of codes to visualize the problem:
Steps to Reproduce
Sent 2 different request using 2 different CurlRequest Instance.
The first one sent using "json" option to set the body
The second one is sent after the first one is finished
Use the "body" option to set the body
The second curl request will send the first body of the first request
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
class Home extends Controller
{
public function index()
{
return view('welcome_message');
}
public function printBody(){
print($this->request->getBody());
}
public function testCurl(){
// Fixed variables (url etc)
$url = "http://localhost:8083/printBody"; // url for the printbody function above
// Text Body 1
$text_body_1 = ["data"=> "testing", "message" => "This the 1st request body"];
print("First Body = '".json_encode($text_body_1)."'<br>");
// Text Body 2
$text_body_2 = "This is the 2nd Request Body";
print("Second Body = '".$text_body_2."'<br>");
// First Request
$client_1 = \Config\Services::curlrequest();
$response_1 = $client_1->request(
'post',
$url,
[
"json" => $text_body_1,
'http_errors' => false
],
);
print("First Response = '".$response_1->getBody()."'<br>");
// Second Request
$client_2 = \Config\Services::curlrequest();
$response_2 = $client_2->request(
'post',
$url,
[
"body" => $text_body_2,
'http_errors' => false
],
);
print("Second Response = '".$response_2->getBody()."'<br>");
}
}
Expected Output
the second request should send the newly set http request body
PHP Version
8.2
CodeIgniter4 Version
4.3.6
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
no Database
What happened?
Hi, I found this behavior accidentally where once a request was sent using "json" parameters, the next curl request will have it's "body" parameters overriden by the previous request configuration.
This might relate to CURLRequest.php line 638 or parseOptions methods on CURLRequest.php.
Here's a snippet of codes to visualize the problem:
Steps to Reproduce
Sent 2 different request using 2 different CurlRequest Instance.
Expected Output
the second request should send the newly set http request body
Anything else?
No response