Permalink
Browse files

Merge pull request #590 from fellars/dev

modified curl to support options
  • Loading branch information...
2 parents 9f32ba3 + 9a33ac7 commit ff59bc653451ee24e794177f7ed8cd5ccd572951 @gwoo gwoo committed Jul 22, 2012
Showing with 17 additions and 0 deletions.
  1. +4 −0 net/socket/Curl.php
  2. +13 −0 tests/cases/net/socket/CurlTest.php
View
@@ -50,6 +50,7 @@ public function __construct(array $config = array()) {
* Opens a curl connection and initializes the internal resource handle.
*
* @param array $options update the config settings
+ * if $options['options'] exists, will be passed to $this->set()
* @return mixed Returns `false` if the socket configuration does not contain the
* `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
* resource stream.
@@ -62,6 +63,9 @@ public function open(array $options = array()) {
if (empty($config['scheme']) || empty($config['host'])) {
return false;
}
+ if (!empty($config['options'])) {
+ $this->set($config['options']);
+ }
$url = "{$config['scheme']}://{$config['host']}";
$this->_resource = curl_init($url);
@@ -140,6 +140,19 @@ public function testSettingOfOptions() {
$this->assertEqual('Changed Dummy Value', $stream->options['DummyFlag']);
}
+ public function testSettingOfOptionsInConfig() {
+ $this->_testConfig['options'] = array('DummyFlag'=> 'Dummy Value');
+ $stream = new Curl($this->_testConfig);
+ $stream->open();
+ $this->assertEqual('Dummy Value', $stream->options['DummyFlag']);
+ }
+
+ public function testSettingOfOptionsInOpen() {
+ $stream = new Curl($this->_testConfig);
+ $stream->open(array('options'=>array('DummyFlag'=> 'Dummy Value')));
+ $this->assertEqual('Dummy Value', $stream->options['DummyFlag']);
+ }
+
public function testSendPostThenGet() {
$postConfig = array('method' => 'POST', 'body' => '{"body"}');
$stream = new Curl($this->_testConfig);

0 comments on commit ff59bc6

Please sign in to comment.