Skip to content

Commit aac88a0

Browse files
committed
fix: CURLRequest request body is not reset on the next request
1 parent a034bcb commit aac88a0

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

system/HTTP/CURLRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ protected function resetOptions()
151151
$this->headers = [];
152152
$this->headerMap = [];
153153

154+
// Reset body
155+
$this->body = null;
156+
154157
// Reset configs
155158
$this->config = $this->defaultConfig;
156159

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,21 @@ public function testApplyBody()
807807
$this->assertSame('name=George', $request->curl_options[CURLOPT_POSTFIELDS]);
808808
}
809809

810+
public function testBodyIsResstOnSecondRequest()
811+
{
812+
$request = $this->getRequest([
813+
'base_uri' => 'http://www.foo.com/api/v1/',
814+
'delay' => 100,
815+
]);
816+
$request->setBody('name=George');
817+
$request->setOutput('Hi there');
818+
819+
$request->post('answer');
820+
$request->post('answer');
821+
822+
$this->assertArrayNotHasKey(CURLOPT_POSTFIELDS, $request->curl_options);
823+
}
824+
810825
public function testResponseHeaders()
811826
{
812827
$request = $this->getRequest([
@@ -922,7 +937,10 @@ public function testJSONData()
922937
$this->assertSame('post', $this->request->getMethod());
923938

924939
$expected = json_encode($params);
925-
$this->assertSame($expected, $this->request->getBody());
940+
$this->assertSame(
941+
$expected,
942+
$this->request->curl_options[CURLOPT_POSTFIELDS]
943+
);
926944
}
927945

928946
public function testSetJSON()
@@ -936,7 +954,12 @@ public function testSetJSON()
936954
];
937955
$this->request->setJSON($params)->post('/post');
938956

939-
$this->assertSame(json_encode($params), $this->request->getBody());
957+
$expected = json_encode($params);
958+
$this->assertSame(
959+
$expected,
960+
$this->request->curl_options[CURLOPT_POSTFIELDS]
961+
);
962+
940963
$this->assertSame(
941964
'Content-Type: application/json',
942965
$this->request->curl_options[CURLOPT_HTTPHEADER][0]

0 commit comments

Comments
 (0)