You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jk...@apache.org on 2017/02/09 20:13:26 UTC

thrift git commit: THRIFT-4072 php: TCurlClient - Add the possibility to send custom headers Client: php

Repository: thrift
Updated Branches:
  refs/heads/master f53505857 -> 3590f1e7c


THRIFT-4072 php: TCurlClient - Add the possibility to send custom headers
Client: php

This closes #1178


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3590f1e7
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3590f1e7
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3590f1e7

Branch: refs/heads/master
Commit: 3590f1e7ca49c3eea879008d510023edf30b6408
Parents: f535058
Author: Swati Kumar <sw...@thumbtack.com>
Authored: Tue Feb 7 16:43:45 2017 -0800
Committer: James E. King, III <jk...@apache.org>
Committed: Thu Feb 9 15:12:47 2017 -0500

----------------------------------------------------------------------
 lib/php/lib/Thrift/Transport/TCurlClient.php | 24 ++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3590f1e7/lib/php/lib/Thrift/Transport/TCurlClient.php
----------------------------------------------------------------------
diff --git a/lib/php/lib/Thrift/Transport/TCurlClient.php b/lib/php/lib/Thrift/Transport/TCurlClient.php
index 4b3e694..c761cd0 100644
--- a/lib/php/lib/Thrift/Transport/TCurlClient.php
+++ b/lib/php/lib/Thrift/Transport/TCurlClient.php
@@ -84,6 +84,13 @@ class TCurlClient extends TTransport
   protected $timeout_;
 
   /**
+   * http headers
+   *
+   * @var array
+   */
+  protected $headers_;
+
+  /**
    * Make a new HTTP client.
    *
    * @param string $host
@@ -102,6 +109,7 @@ class TCurlClient extends TTransport
     $this->request_ = '';
     $this->response_ = null;
     $this->timeout_ = null;
+    $this->headers_ = array();
   }
 
   /**
@@ -193,9 +201,14 @@ class TCurlClient extends TTransport
     $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
     $fullUrl = $this->scheme_."://".$host.$this->uri_;
 
-    $headers = array('Accept: application/x-thrift',
-                     'Content-Type: application/x-thrift',
-                     'Content-Length: '.TStringFuncFactory::create()->strlen($this->request_));
+    $headers = array();
+    $defaultHeaders = array('Accept' => 'application/x-thrift',
+                     'Content-Type' => 'application/x-thrift',
+                     'Content-Length' => TStringFuncFactory::create()->strlen($this->request_));
+    foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) {
+      $headers[] = "$key: $value";
+    }
+
     curl_setopt(self::$curlHandle, CURLOPT_HTTPHEADER, $headers);
 
     if ($this->timeout_ > 0) {
@@ -228,4 +241,9 @@ class TCurlClient extends TTransport
     }
   }
 
+  public function addHeaders($headers)
+  {
+    $this->headers_ = array_merge($this->headers_, $headers);
+  }
+
 }