You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2013/03/23 16:08:57 UTC

git commit: THRIFT-1878 php: THttpClient - Add the possibility to send custom headers Patch: Laurent Sarrazin

Updated Branches:
  refs/heads/master a7ab94d41 -> 1f9717d19


THRIFT-1878 php: THttpClient - Add the possibility to send custom headers
Patch: Laurent Sarrazin


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

Branch: refs/heads/master
Commit: 1f9717d192137d06927846cc2f2f7e380e5da834
Parents: a7ab94d
Author: Roger Meier <ro...@apache.org>
Authored: Sat Mar 23 16:03:38 2013 +0100
Committer: Roger Meier <ro...@apache.org>
Committed: Sat Mar 23 16:03:38 2013 +0100

----------------------------------------------------------------------
 lib/php/lib/Thrift/Transport/THttpClient.php |   26 +++++++++++++++++----
 1 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/1f9717d1/lib/php/lib/Thrift/Transport/THttpClient.php
----------------------------------------------------------------------
diff --git a/lib/php/lib/Thrift/Transport/THttpClient.php b/lib/php/lib/Thrift/Transport/THttpClient.php
index 87f2871..f46b18a 100644
--- a/lib/php/lib/Thrift/Transport/THttpClient.php
+++ b/lib/php/lib/Thrift/Transport/THttpClient.php
@@ -83,6 +83,13 @@ class THttpClient extends TTransport {
   protected $timeout_;
 
   /**
+   * http headers
+   *
+   * @var array
+   */
+  protected $headers_;
+
+  /**
    * Make a new HTTP client.
    *
    * @param string $host
@@ -100,6 +107,7 @@ class THttpClient extends TTransport {
     $this->buf_ = '';
     $this->handle_ = null;
     $this->timeout_ = null;
+    $this->headers_ = array();
   }
 
   /**
@@ -176,11 +184,15 @@ class THttpClient extends TTransport {
     // God, PHP really has some esoteric ways of doing simple things.
     $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
 
-    $headers = array('Host: '.$host,
-                     'Accept: application/x-thrift',
-                     'User-Agent: PHP/THttpClient',
-                     'Content-Type: application/x-thrift',
-                     'Content-Length: '.TStringFuncFactory::create()->strlen($this->buf_));
+    $headers = array();
+    $defaultHeaders = array('Host' => $host,
+                            'Accept' => 'application/x-thrift',
+                            'User-Agent' => 'PHP/THttpClient',
+                            'Content-Type' => 'application/x-thrift',
+                            'Content-Length' => TStringFuncFactory::create()->strlen($this->buf_));
+    foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) {
+        $headers[] = "$key: $value";
+    }
 
     $options = array('method' => 'POST',
                      'header' => implode("\r\n", $headers),
@@ -202,4 +214,8 @@ class THttpClient extends TTransport {
     }
   }
 
+  public function addHeaders($headers) {
+    $this->headers_ = array_merge($this->headers_, $headers);
+  }
+
 }