[ https://issues.apache.org/jira/browse/THRIFT-4674?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16701353#comment-16701353 ]
ASF GitHub Bot commented on THRIFT-4674: ---------------------------------------- jeking3 closed pull request #1636: THRIFT-4674 Added stream context support for PHP THttpClient URL: https://github.com/apache/thrift/pull/1636 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/lib/php/lib/Transport/THttpClient.php b/lib/php/lib/Transport/THttpClient.php index a89794b086..0158809d29 100644 --- a/lib/php/lib/Transport/THttpClient.php +++ b/lib/php/lib/Transport/THttpClient.php @@ -88,14 +88,23 @@ 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 @@ public function __construct($host, $port = 80, $uri = '', $scheme = 'http') $this->handle_ = null; $this->timeout_ = null; $this->headers_ = array(); + $this->context_ = $context; } /** @@ -211,16 +221,21 @@ public function flush() $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', ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add stream context support into PHP/THttpClient > ----------------------------------------------- > > Key: THRIFT-4674 > URL: https://issues.apache.org/jira/browse/THRIFT-4674 > Project: Thrift > Issue Type: Improvement > Reporter: Evgeniy Efimov > Priority: Major > Fix For: 1.0 > > > In some use-cases it is required to pass additional data into context for > THttpClient, client certificate as an example. > See PR: https://github.com/apache/thrift/pull/1636 -- This message was sent by Atlassian JIRA (v7.6.3#76005)