|
18 | 18 | use Http\Discovery\StreamFactoryDiscovery; |
19 | 19 | use Http\Discovery\UriFactoryDiscovery; |
20 | 20 | use Http\Message\MessageFactory; |
21 | | -use Http\Message\SteamFactory; |
| 21 | +use Nyholm\Psr7\Factory\StreamFactory; |
22 | 22 | use Psr\Cache\CacheItemPoolInterface; |
23 | 23 |
|
24 | 24 | /** |
@@ -309,7 +309,7 @@ public function setEnterpriseUrl($enterpriseUrl) |
309 | 309 | } |
310 | 310 |
|
311 | 311 | /** |
312 | | - * Add a new plugin to the chain |
| 312 | + * Add a new plugin to the end of the plugin chain. |
313 | 313 | * |
314 | 314 | * @param Plugin $plugin |
315 | 315 | */ |
@@ -341,6 +341,8 @@ public function getHttpClient() |
341 | 341 | { |
342 | 342 | if ($this->httpClientModified) { |
343 | 343 | $this->httpClientModified = false; |
| 344 | + $this->pushBackCachePlugin(); |
| 345 | + |
344 | 346 | $this->pluginClient = new HttpMethodsClient( |
345 | 347 | new PluginClient($this->httpClient, $this->plugins), |
346 | 348 | $this->messageFactory |
@@ -457,4 +459,22 @@ public function getLastResponse() |
457 | 459 | { |
458 | 460 | return $this->responseHistory->getLastResponse(); |
459 | 461 | } |
| 462 | + |
| 463 | + /** |
| 464 | + * Make sure to move the cache plugin to the end of the chain |
| 465 | + */ |
| 466 | + private function pushBackCachePlugin() |
| 467 | + { |
| 468 | + $cachePlugin = null; |
| 469 | + foreach ($this->plugins as $i => $plugin) { |
| 470 | + if ($plugin instanceof Plugin\CachePlugin) { |
| 471 | + $cachePlugin = $plugin; |
| 472 | + unset($this->plugins[$i]); |
| 473 | + |
| 474 | + $this->plugins[] = $cachePlugin; |
| 475 | + |
| 476 | + return; |
| 477 | + } |
| 478 | + } |
| 479 | + } |
460 | 480 | } |
0 commit comments