Skip to content

Commit c9bac5f

Browse files
committed
fix: reset $unsharedHeaders after sending request
If user setHeader() that is defined in $unsharedHeaders, the header will be removed before sending request, and there is no way to send the header. The reason I didn't do the reset after sending is because a test failed. This time I modify the test, too.
1 parent 9cbe0f2 commit c9bac5f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

system/HTTP/CURLRequest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
116116
*/
117117
public function request($method, string $url, array $options = []): ResponseInterface
118118
{
119-
// Reset unshared headers
120-
foreach ($this->unsharedHeaders as $header) {
121-
$this->removeHeader($header);
122-
}
123-
124119
$this->parseOptions($options);
125120

126121
$url = $this->prepareURL($url);
@@ -129,6 +124,10 @@ public function request($method, string $url, array $options = []): ResponseInte
129124

130125
$this->send($method, $url);
131126

127+
// Reset unshared headers
128+
foreach ($this->unsharedHeaders as $header) {
129+
$this->removeHeader($header);
130+
}
132131
// Reset unshared configs
133132
unset($this->config['multipart'], $this->config['form_params']);
134133

tests/system/HTTP/CURLRequestTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,10 @@ public function testSetJSON()
912912
$this->request->setJSON($params)->post('/post');
913913

914914
$this->assertSame(json_encode($params), $this->request->getBody());
915-
$this->assertSame('application/json', $this->request->getHeaderLine('Content-Type'));
915+
$this->assertSame(
916+
'Content-Type: application/json',
917+
$this->request->curl_options[CURLOPT_HTTPHEADER][0]
918+
);
916919
}
917920

918921
public function testHTTPv1()

0 commit comments

Comments
 (0)