summaryrefslogtreecommitdiff
path: root/lib/php
diff options
context:
space:
mode:
authorEfimov Evgenij <edefimov.it@gmail.com>2018-11-23 10:57:42 +0300
committerJames E. King III <jking@apache.org>2018-11-27 22:19:24 -0500
commit7f0fa6c21ec225aebbbc563607646124279e557c (patch)
treefcb1cd740fce862ac7bd51168eba97ff5d9564ff /lib/php
parentb073e1438d9236203c70efb5b3ba55a61f4c4d14 (diff)
downloadthrift-7f0fa6c21ec225aebbbc563607646124279e557c.tar.gz
THRIFT-4674 Added stream context support for PHP THttpClient
Diffstat (limited to 'lib/php')
-rw-r--r--lib/php/lib/Transport/THttpClient.php25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/php/lib/Transport/THttpClient.php b/lib/php/lib/Transport/THttpClient.php
index a89794b08..0158809d2 100644
--- a/lib/php/lib/Transport/THttpClient.php
+++ b/lib/php/lib/Transport/THttpClient.php
@@ -89,13 +89,22 @@ class THttpClient extends TTransport
protected $headers_;
/**
+ * Context additional options
+ *
+ * @var array
+ */
+ protected $context_;
+
+ /**
* Make a new HTTP client.
*
* @param string $host
- * @param int $port
+ * @param int $port
* @param string $uri
+ * @param string $scheme
+ * @param array $context
*/
- public function __construct($host, $port = 80, $uri = '', $scheme = 'http')
+ public function __construct($host, $port = 80, $uri = '', $scheme = 'http', array $context = array())
{
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
$uri = '/' . $uri;
@@ -108,6 +117,7 @@ class THttpClient extends TTransport
$this->handle_ = null;
$this->timeout_ = null;
$this->headers_ = array();
+ $this->context_ = $context;
}
/**
@@ -211,16 +221,21 @@ class THttpClient extends TTransport
$headers[] = "$key: $value";
}
- $options = array('method' => 'POST',
+ $options = $this->context_;
+
+ $baseHttpOptions = isset($options["http"]) ? $options["http"] : array();
+
+ $httpOptions = $baseHttpOptions + array('method' => 'POST',
'header' => implode("\r\n", $headers),
'max_redirects' => 1,
'content' => $this->buf_);
if ($this->timeout_ > 0) {
- $options['timeout'] = $this->timeout_;
+ $httpOptions['timeout'] = $this->timeout_;
}
$this->buf_ = '';
- $contextid = stream_context_create(array('http' => $options));
+ $options["http"] = $httpOptions;
+ $contextid = stream_context_create($options);
$this->handle_ = @fopen(
$this->scheme_ . '://' . $host . $this->uri_,
'r',