*/
protected $timeout_;
+ /**
+ * http headers
+ *
+ * @var array
+ */
+ protected $headers_;
+
/**
* Make a new HTTP client.
*
$this->buf_ = '';
$this->handle_ = null;
$this->timeout_ = null;
+ $this->headers_ = array();
}
/**
// 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),
}
}
+ public function addHeaders($headers) {
+ $this->headers_ = array_merge($this->headers_, $headers);
+ }
+
}