Skip to content

Commit 9813b9b

Browse files
committed
#7: Use cURL constants as options keys
1 parent 459dca3 commit 9813b9b

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/CurlHttpClient.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
class CurlHttpClient implements HttpClient, HttpAsyncClient
2626
{
2727
/**
28-
* Client settings
28+
* cURL options
2929
*
3030
* @var array
3131
*/
32-
private $settings;
32+
private $options;
3333

3434
/**
3535
* cURL response parser
@@ -64,7 +64,7 @@ class CurlHttpClient implements HttpClient, HttpAsyncClient
6464
*
6565
* @param MessageFactory $messageFactory HTTP Message factory
6666
* @param StreamFactory $streamFactory HTTP Stream factory
67-
* @param array $options Client options
67+
* @param array $options cURL options (see http://php.net/curl_setopt)
6868
*
6969
* @since 1.0
7070
*/
@@ -74,15 +74,7 @@ public function __construct(
7474
array $options = []
7575
) {
7676
$this->responseParser = new ResponseParser($messageFactory, $streamFactory);
77-
$this->settings = array_merge(
78-
[
79-
'curl_options' => [],
80-
'connection_timeout' => 3,
81-
'ssl_verify_peer' => true,
82-
'timeout' => 10
83-
],
84-
$options
85-
);
77+
$this->options = $options;
8678
}
8779

8880
/**
@@ -169,19 +161,15 @@ public function sendAsyncRequest(RequestInterface $request)
169161
*/
170162
private function createCurlOptions(RequestInterface $request)
171163
{
172-
$options = $this->settings['curl_options'];
164+
$options = $this->options;
173165

174166
$options[CURLOPT_HEADER] = true;
175167
$options[CURLOPT_RETURNTRANSFER] = true;
168+
$options[CURLOPT_FOLLOWLOCATION] = false;
176169

177170
$options[CURLOPT_HTTP_VERSION] = $this->getProtocolVersion($request->getProtocolVersion());
178171
$options[CURLOPT_URL] = (string) $request->getUri();
179172

180-
$options[CURLOPT_CONNECTTIMEOUT] = $this->settings['connection_timeout'];
181-
$options[CURLOPT_FOLLOWLOCATION] = false;
182-
$options[CURLOPT_SSL_VERIFYPEER] = $this->settings['ssl_verify_peer'];
183-
$options[CURLOPT_TIMEOUT] = $this->settings['timeout'];
184-
185173
if (in_array($request->getMethod(), ['OPTIONS', 'POST', 'PUT'], true)) {
186174
// cURL allows request body only for these methods.
187175
$body = (string) $request->getBody();

0 commit comments

Comments
 (0)