Add a HTTP stream based HTTP client for environments that lack cURL. #124

Closed
wants to merge 16 commits into
from

Projects

None yet

4 participants

@sjlangley
Contributor

As cURL is an optional extension not all host have it enabled.

This falls back to a http streams based approach to making HTTP requests is cURL is not detected.

@caseysoftware

Minor typo.. this should be:

verify_peer

Owner

Yes, please fix so we can get it all in one shot.

@caseysoftware caseysoftware commented on the diff Jun 6, 2013
Services/Twilio/Resource.php
@@ -87,7 +87,10 @@ public static function decamelize($word)
* @return string
*/
public static function camelize($word) {
- return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);
@caseysoftware
caseysoftware Jun 6, 2013 Contributor

As written here, using the anonymous function breaks PHP 5.2 compatibility.

By using create_function - as in my pull request: #123 - we fix the /e issue and keep 5.2 compatibility.

@sjlangley
sjlangley Jun 6, 2013 Contributor

I can revert this then you can merge the other pull request - let me know what's best.

@caseysoftware
Contributor

Testing complete, this is good.
I'm 100% in favor of merging this pull request given my two notes above.

@kevinburke kevinburke and 2 others commented on an outdated diff Jun 6, 2013
Services/Twilio.php
+ CURLOPT_USERAGENT => self::USER_AGENT,
+ CURLOPT_HTTPHEADER => array('Accept-Charset: utf-8'),
+ CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem',
+ ))
+ );
+ } else {
+ $_http = new Services_Twilio_HttpStream(
+ "https://api.twilio.com",
+ array(
+ "http_options" => array(
+ "http" => array(
+ "user_agent" => self::USER_AGENT,
+ "header" => "Accept-Charset: utf-8\r\n",
+ ),
+ "ssl" => array(
+ 'veryify_peer' => true,
@kevinburke
kevinburke Jun 6, 2013 Contributor

Looks like there's a typo here.

@caseysoftware
caseysoftware Jun 6, 2013 Contributor

As noted above. @sjlangley will fix.

@sjlangley
sjlangley Jun 6, 2013 Contributor

done

@kevinburke kevinburke and 1 other commented on an outdated diff Jun 6, 2013
Services/Twilio/HttpStream.php
+ private $debug = false;
+ private static $default_options = array(
+ "http" => array(
+ "headers" => "",
+ "timeout" => 60,
+ "follow_location" => true,
+ "ignore_errors" => true,
+ ),
+ "ssl" => array(),
+ );
+ private $options = array();
+
+ public function __construct($uri = '', $kwargs = array()) {
+ $this->uri = $uri;
+ if (isset($kwargs['debug'])) {
+ $this->debug = false;
@kevinburke
kevinburke Jun 6, 2013 Contributor

This line is a little odd... do you mean to write

$this->debug = $kwargs['debug'];
@sjlangley
sjlangley Jun 6, 2013 Contributor

done

@kevinburke kevinburke commented on the diff Jun 6, 2013
Services/Twilio/HttpStream.php
+
+ foreach($req_headers as $key => $value) {
+ $request_options['http']['header'] .= sprintf("%s: %s\r\n", $key, $value);
+ }
+
+ if (isset($this->auth_header)) {
+ $request_options['http']['header'] .= $this->auth_header;
+ }
+
+ $request_options['http']['method'] = strtoupper($name);
+
+ $ctx = stream_context_create($request_options);
+ $result = file_get_contents($url, false, $ctx);
+
+ if (false === $result) {
+ throw new Services_Twilio_HttpStreamException(
@kevinburke
kevinburke Jun 6, 2013 Contributor

I'm thinking here that we should create a generic HttpException class that both the TinyHttp and the HttpStream class raise in the event of an exception.

@sjlangley
sjlangley Jun 6, 2013 Contributor

I don't see Services_Twilio_TinyHttpException being caught anywhere

@sjlangley sjlangley - Fix typo in ssl options
- Fix debug flag and print debug output if the flag is on.
814ce39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment