Skip to content

Commit f2b1a77

Browse files
committed
Removed support for default headers in the builder
1 parent 7153101 commit f2b1a77

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

lib/Github/Client.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,15 @@ class Client
111111
public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
112112
{
113113
$this->responseHistory = new History();
114-
$this->httpClientBuilder = $httpClientBuilder ?: new Builder();
115-
$this->getHttpClientBuilder()->addDefaultHeaders([
116-
'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()),
117-
]);
114+
$this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder();
118115

119-
$this->getHttpClientBuilder()->addPlugin(new GithubExceptionThrower());
120-
$this->getHttpClientBuilder()->addPlugin(new Plugin\HistoryPlugin($this->responseHistory));
121-
$this->getHttpClientBuilder()->addPlugin(new Plugin\RedirectPlugin());
122-
$this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com')));
123-
$this->getHttpClientBuilder()->addPlugin(new Plugin\HeaderDefaultsPlugin(array(
116+
$builder->addPlugin(new GithubExceptionThrower());
117+
$builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory));
118+
$builder->addPlugin(new Plugin\RedirectPlugin());
119+
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com')));
120+
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin(array(
124121
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
122+
'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()),
125123
)));
126124

127125
$this->apiVersion = $apiVersion ?: 'v3';
@@ -290,11 +288,12 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null
290288
*/
291289
private function setEnterpriseUrl($enterpriseUrl)
292290
{
293-
$this->getHttpClientBuilder()->removePlugin(Plugin\AddHostPlugin::class);
294-
$this->getHttpClientBuilder()->removePlugin(PathPrepend::class);
291+
$builder = $this->getHttpClientBuilder();
292+
$builder->removePlugin(Plugin\AddHostPlugin::class);
293+
$builder->removePlugin(PathPrepend::class);
295294

296-
$this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl)));
297-
$this->getHttpClientBuilder()->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion())));
295+
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl)));
296+
$builder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion())));
298297
}
299298

300299
/**

lib/Github/HttpClient/Builder.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ class Builder
7272
*/
7373
private $headers = [];
7474

75-
/**
76-
* Headers that will always be in the client.
77-
*
78-
* @var array
79-
*/
80-
private $defaultHeaders = [];
81-
8275
/**
8376
* @param HttpClient $httpClient
8477
* @param RequestFactory $requestFactory
@@ -147,7 +140,7 @@ public function removePlugin($fqcn)
147140
*/
148141
public function clearHeaders()
149142
{
150-
$this->headers = $this->defaultHeaders;
143+
$this->headers = [];
151144

152145
$this->removePlugin(Plugin\HeaderAppendPlugin::class);
153146
$this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers));
@@ -164,19 +157,6 @@ public function addHeaders(array $headers)
164157
$this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers));
165158
}
166159

167-
/**
168-
* Add default headers. Default headers will not be cleared when calling clearHeaders.
169-
*
170-
* @param array $headers
171-
*/
172-
public function addDefaultHeaders(array $headers)
173-
{
174-
$this->defaultHeaders = array_merge($this->defaultHeaders, $headers);
175-
176-
$this->removePlugin(Plugin\HeaderAppendPlugin::class);
177-
$this->addPlugin(new Plugin\HeaderAppendPlugin(array_merge($this->defaultHeaders, $this->headers)));
178-
}
179-
180160
/**
181161
* Add a cache plugin to cache responses locally.
182162
*

0 commit comments

Comments
 (0)