Skip to content

Commit

Permalink
update some for http client
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 16, 2020
1 parent 4ca5e11 commit b11a43a
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ class HttpClient
* [
* 'method' => 'GET',
* 'data' => 'string|array',
* 'headers' => [key => value],
* 'cookies' => [key => value],
* 'settings' => [key => value],
* ]
*
* @var array
*/
private $options = [];

/**
* @var array [key => value]
*/
private $cookies = [];

/**
* @var array [key => value]
*/
private $headers = [];

/**
* @var string
*/
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit b11a43a

Please sign in to comment.