Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from phergie/fix-request-headers
Browse files Browse the repository at this point in the history
Fix not passing request headers to client
  • Loading branch information
WyriHaximus authored Jan 21, 2017
2 parents 25a0ccf + 416468e commit 98c76ca
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function (Client $client) use ($request) {
$requestObject = $client->createRequest($request->getMethod(), $request->getUrl(), [
'future' => true,
'stream' => false,
'headers' => $request->getHeaders(),
]);
$this->logDebug('[' . $requestId . ']Sending request');
$client->send($requestObject)->then(function ($response) use ($requestId, $request) {
Expand All @@ -139,6 +140,7 @@ function (Client $client) use ($request) {
$requestObject = $client->createRequest($request->getMethod(), $request->getUrl(), [
'future' => true,
'stream' => true,
'headers' => $request->getHeaders(),
]);
$this->logDebug('[' . $requestId . ']Sending request');
$client->send($requestObject)->then(function ($response) use ($requestId, $request) {
Expand Down
110 changes: 110 additions & 0 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,116 @@ public function testMakeStreamingHttpRequest()
]
);

$guzzleClient->expects($this->once())
->method('send')
->with($this->isInstanceOf('GuzzleHttp\Message\RequestInterface'))
->willReturn(new FulfilledPromise());

$plugin = new Plugin();
$plugin->setGuzzleClient($guzzleClient);
$plugin->setLogger($this->getMock('Psr\Log\LoggerInterface'));
$plugin->makeStreamingHttpRequest($request);
}
public function testMakeHttpRequestWithHeaders()
{
$request = $this->getMock(
'\Phergie\Plugin\Http\Request',
[
'getHeaders'
],
[
[
'url' => 'http://example.com/',
'headers' => [
'Accept' => 'text/html'
],
'resolveCallback' => function () {
}
]
]
);

$httpClientAdapter = $this->getMock(
'WyriHaximus\React\RingPHP\HttpClientAdapter',
[
'__invoke',
],
[
$this->getMock('React\EventLoop\LoopInterface'),
]
);

$guzzleClient = $this->getMock(
'GuzzleHttp\Client',
[
'send',
],
[
[
'handler' => $httpClientAdapter,
],
]
);

$request->expects($this->once())
->method('getHeaders')
->willReturn(['Accept' => 'text/html']);

$guzzleClient->expects($this->once())
->method('send')
->with($this->isInstanceOf('GuzzleHttp\Message\RequestInterface'))
->willReturn(new FulfilledPromise());

$plugin = new Plugin();
$plugin->setGuzzleClient($guzzleClient);
$plugin->setLogger($this->getMock('Psr\Log\LoggerInterface'));
$plugin->makeHttpRequest($request);
}
public function testMakeStreamingHttpRequestWithHeaders()
{
$request = $this->getMock(
'\Phergie\Plugin\Http\Request',
[
'getHeaders'
],
[
[
'url' => 'http://example.com/',
'headers' => [
'Accept' => 'text/html'
],
'resolveCallback' => function () {
}
]
]
);

$httpClientAdapter = $this->getMock(
'WyriHaximus\React\RingPHP\HttpClientAdapter',
[
'__invoke',
],
[
$this->getMock('React\EventLoop\LoopInterface'),
]
);

$guzzleClient = $this->getMock(
'GuzzleHttp\Client',
[
'send',
],
[
[
'handler' => $httpClientAdapter,
],
]
);

$request->expects($this->once())
->method('getHeaders')
->willReturn(['Accept' => 'text/html']);

$guzzleClient->expects($this->once())
->method('send')
->with($this->isInstanceOf('GuzzleHttp\Message\RequestInterface'))
Expand Down

0 comments on commit 98c76ca

Please sign in to comment.