Skip to content

Commit 613b980

Browse files
committed
fix: remove $unsharedHeaders and add $defaultOptions
$defaultOptions is options passed in the constructor. They are applied for all requests. All request headers are cleared after sending request, and $defaultOptions are set again.
1 parent 9a6a0d3 commit 613b980

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

system/HTTP/CURLRequest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ class CURLRequest extends Request
7373
protected $delay = 0.0;
7474

7575
/**
76-
* Request headers that are not shared between requests.
76+
* Default options. Applied to all requests.
7777
*
78-
* @var string[]
78+
* @var array
7979
*/
80-
protected $unsharedHeaders = [
81-
'Content-Length',
82-
'Content-Type',
83-
];
80+
private $defaultOptions;
8481

8582
/**
8683
* Takes an array of options to set the following possible class properties:
@@ -102,8 +99,9 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
10299

103100
parent::__construct($config);
104101

105-
$this->response = $response;
106-
$this->baseURI = $uri->useRawQueryString();
102+
$this->response = $response;
103+
$this->baseURI = $uri->useRawQueryString();
104+
$this->defaultOptions = $options;
107105

108106
$this->parseOptions($options);
109107
}
@@ -124,12 +122,13 @@ public function request($method, string $url, array $options = []): ResponseInte
124122

125123
$this->send($method, $url);
126124

127-
// Reset unshared headers
128-
foreach ($this->unsharedHeaders as $header) {
129-
$this->removeHeader($header);
130-
}
125+
// Reset headers
126+
$this->headers = [];
127+
$this->headerMap = [];
131128
// Reset unshared configs
132129
unset($this->config['multipart'], $this->config['form_params']);
130+
// Set the default options for next request
131+
$this->parseOptions($this->defaultOptions);
133132

134133
return $this->response;
135134
}

0 commit comments

Comments
 (0)