The trunk PHP library doesn't support HTTPS transport via THttpClient.php. I've attached a relatively small change to this class that adds an optional fourth constructor parameter ('protocol') which can be used to specify 'http' or 'https'.

Usage:

$transport = new THttpClient('www.evernote.com', 80, '/edam/user', 'http'); $sslTransport = new THttpClient('www.evernote.com', 443, '/edam/user', 'https');

This change should be backward compatible with existing code:

   $transport = new THttpClient('www.evernote.com', 80, '/edam/user');


Please let me know if this mailing list isn't the right way to submit patches ... I somehow managed to lose track of the mailing list when it went into incubation at Apache, so I'm a few months out of it.

Thanks

Index: lib/php/src/transport/THttpClient.php
===================================================================
--- lib/php/src/transport/THttpClient.php       (revision 1242)
+++ lib/php/src/transport/THttpClient.php       (working copy)
@@ -20,6 +20,13 @@
 class THttpClient extends TTransport {
 
   /**
+   * The protocol to use to talk to the server (http or https)
+   *
+   * @var string
+   */
+  protected $protocol_;
+
+  /**
    * The host to connect to
    *
    * @var string
@@ -67,13 +74,21 @@
    * @param string $host
    * @param int    $port
    * @param string $uri
+   * @param string $protocol
    */
-  public function __construct($host, $port=80, $uri='') {
+  public function __construct($host, $port=0, $uri='', $protocol='http') {
     if ((strlen($uri) > 0) && ($uri{0} != '/')) {
       $uri = '/'.$uri;
     }
+    $this->protocol_ = $protocol;
     $this->host_ = $host;
-    $this->port_ = $port;
+    if ($port > 0) {
+      $this->port_ = $port;
+    } elseif ($protocol === 'https') {
+      $this->port_ = 443;
+    } else {
+      $this->port_ = 80;
+    }
     $this->uri_ = $uri;
     $this->buf_ = '';
     $this->handle_ = null;
@@ -151,8 +166,12 @@
    * @throws TTransportException if a writing error occurs
    */
   public function flush() {
-    // God, PHP really has some esoteric ways of doing simple things.
-    $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
+    $protocol = $this->protocol_;
+    $host = $this->host_;
+    if ((($protocol === 'http') && ($this->port_ != 80)) ||
+        (($protocol === 'https') && ($this->port_ != 443))) {
+      $host = $host.':'.$this->port_;
+    }
 
     $headers = array('Host: '.$host,
                      'Accept: application/x-thrift',
@@ -170,7 +189,8 @@
     $this->buf_ = '';
 
     $contextid = stream_context_create(array('http' => $options));
-    $this->handle_ = @fopen('http://'.$host.$this->uri_, 'r', false, 
$contextid);
+    $url = $protocol.'://'.$host.$this->uri_;
+    $this->handle_ = @fopen($url, 'r', false, $contextid);
 
     // Connect failed?
     if ($this->handle_ === FALSE) {

Reply via email to