Skip to content

Commit 335a7eb

Browse files
committed
Added httpHeader support for http client
1 parent e354d26 commit 335a7eb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Hprose/Http/Client.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ protected function setUri($uri) {
179179
$this->keepAlive = true;
180180
$this->keepAliveTimeout = 300;
181181
}
182-
private function initCurl($curl, $request, $timeout) {
182+
private function initCurl($curl, $request, $context) {
183+
$timeout = $context->timeout;
183184
foreach ($this->options as $name => $value) {
184185
curl_setopt($curl, $name, $value);
185186
}
@@ -202,6 +203,13 @@ private function initCurl($curl, $request, $timeout) {
202203
foreach ($this->header as $name => $value) {
203204
$headers_array[] = $name . ": " . $value;
204205
}
206+
if (isset($context->httpHeader)) {
207+
$header = $context->httpHeader;
208+
foreach ($header as $name => $value) {
209+
$headers_array[] = $name . ": " .
210+
(is_array($value) ? join(", ", $value) : $value);
211+
}
212+
}
205213
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers_array);
206214
if ($this->proxy) {
207215
curl_setopt($curl, CURLOPT_PROXY, $this->proxy);
@@ -242,7 +250,7 @@ private function initCurl($curl, $request, $timeout) {
242250
}
243251
private function syncSendAndReceive($request, stdClass $context) {
244252
$curl = curl_init();
245-
$this->initCurl($curl, $request, $context->timeout);
253+
$this->initCurl($curl, $request, $context);
246254
$data = curl_exec($curl);
247255
$errno = curl_errno($curl);
248256
if ($errno) {
@@ -255,7 +263,7 @@ private function syncSendAndReceive($request, stdClass $context) {
255263
private function asyncSendAndReceive($request, stdClass $context) {
256264
$result = new Future();
257265
$curl = curl_init();
258-
$this->initCurl($curl, $request, $context->timeout);
266+
$this->initCurl($curl, $request, $context);
259267
$this->curls[] = $curl;
260268
$this->results[] = $result;
261269
return $result;

0 commit comments

Comments
 (0)