Skip to content

Commit 593c098

Browse files
committed
Allow setting custom Request and Response in HTTP client.
This should allow an easier integration into 3rd party software.
1 parent d5f6246 commit 593c098

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

lib/Bitbucket/API/Http/Client.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ class Client implements ClientInterface
5858
*/
5959
protected $listeners = array();
6060

61+
/**
62+
* @var MessageInterface
63+
*/
64+
protected $responseObj;
65+
66+
/**
67+
* @var RequestInterface
68+
*/
69+
protected $requestObj;
70+
6171
public function __construct(array $options = array(), BuzzClientInterface $client = null)
6272
{
6373
$this->client = (is_null($client)) ? new Curl : $client;
@@ -182,7 +192,7 @@ public function request($endpoint, $params = array(), $method = 'GET', array $he
182192
$request->setContent(is_array($params) ? http_build_query($params) : $params);
183193
}
184194

185-
$response = new Response;
195+
$response = is_object($this->responseObj) ? $this->responseObj : new Response;
186196

187197
$this->executeListeners($request, 'preSend');
188198

@@ -287,6 +297,26 @@ public function getLastResponse()
287297
return $this->lastResponse;
288298
}
289299

300+
/**
301+
* @access public
302+
* @param MessageInterface $response
303+
* @return void
304+
*/
305+
public function setResponse(MessageInterface $response)
306+
{
307+
$this->responseObj = $response;
308+
}
309+
310+
/**
311+
* @access public
312+
* @param RequestInterface $request
313+
* @return void
314+
*/
315+
public function setRequest(RequestInterface $request)
316+
{
317+
$this->requestObj = $request;
318+
}
319+
290320
/**
291321
* @access protected
292322
* @param string $method
@@ -295,7 +325,8 @@ public function getLastResponse()
295325
*/
296326
protected function createRequest($method, $url)
297327
{
298-
$request = new Request($method);
328+
$request = is_object($this->requestObj) ? $this->requestObj : new Request();
329+
$request->setMethod($method);
299330
$request->addHeaders(array(
300331
'User-Agent' => $this->options['user_agent']
301332
));

0 commit comments

Comments
 (0)