mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-4072 php: TCurlClient - Add the possibility to send custom headers
Client: php This closes #1178
This commit is contained in:
parent
f535058572
commit
3590f1e7ca
@ -83,6 +83,13 @@ class TCurlClient extends TTransport
|
||||
*/
|
||||
protected $timeout_;
|
||||
|
||||
/**
|
||||
* http headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers_;
|
||||
|
||||
/**
|
||||
* Make a new HTTP client.
|
||||
*
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user