diff --git a/src/HttpClient.php b/src/HttpClient.php index 505fc3c..3e8eaed 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -46,8 +46,6 @@ class HttpClient * [ * 'method' => 'GET', * 'data' => 'string|array', - * 'headers' => [key => value], - * 'cookies' => [key => value], * 'settings' => [key => value], * ] * @@ -55,6 +53,16 @@ class HttpClient */ private $options = []; + /** + * @var array [key => value] + */ + private $cookies = []; + + /** + * @var array [key => value] + */ + private $headers = []; + /** * @var string */ @@ -216,14 +224,15 @@ private function configRequest(Client $client, array $info, array $options): str /* * [key => value] */ - if ($headers) { + if ($headers = array_merge($this->headers, $headers)) { $client->setHeaders($headers); } /* * [key => value] */ - if ($cookies = $options['cookies'] ?? []) { + $cookies = $options['cookies'] ?? []; + if ($cookies = array_merge($this->cookies, $cookies)) { $client->setCookies($cookies); } @@ -315,4 +324,36 @@ public function setOptions(array $options): self $this->options = $options; return $this; } + + /** + * @return array + */ + public function getHeaders(): array + { + return $this->headers; + } + + /** + * @param array $headers + */ + public function setHeaders(array $headers): void + { + $this->headers = $headers; + } + + /** + * @return array + */ + public function getCookies(): array + { + return $this->cookies; + } + + /** + * @param array $cookies + */ + public function setCookies(array $cookies): void + { + $this->cookies = $cookies; + } }