Skip to content

Commit 4fd093a

Browse files
committed
Add preliminary support for HHVM
1 parent 157893b commit 4fd093a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Curl.class.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function get($url_mixed, $data = array())
9393

9494
public function post($url, $data = array())
9595
{
96+
if (is_array($data) && empty($data)) {
97+
$this->setHeader('Content-Length');
98+
}
99+
96100
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
97101
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
98102
$this->setOpt(CURLOPT_POST, true);
@@ -104,12 +108,17 @@ public function put($url, $data = array())
104108
{
105109
$this->setOpt(CURLOPT_URL, $url);
106110
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
107-
$this->setOpt(CURLOPT_POSTFIELDS, http_build_query($data));
111+
$put_data = http_build_query($data);
112+
if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) {
113+
$this->setHeader('Content-Length', strlen($put_data));
114+
}
115+
$this->setOpt(CURLOPT_POSTFIELDS, $put_data);
108116
return $this->exec();
109117
}
110118

111119
public function patch($url, $data = array())
112120
{
121+
$this->setHeader('Content-Length');
113122
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
114123
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
115124
$this->setOpt(CURLOPT_POSTFIELDS, $data);
@@ -118,6 +127,7 @@ public function patch($url, $data = array())
118127

119128
public function delete($url, $data = array())
120129
{
130+
$this->setHeader('Content-Length');
121131
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
122132
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
123133
return $this->exec();
@@ -133,6 +143,7 @@ public function head($url, $data = array())
133143

134144
public function options($url, $data = array())
135145
{
146+
$this->setHeader('Content-Length');
136147
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
137148
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
138149
return $this->exec();
@@ -144,7 +155,7 @@ public function setBasicAuthentication($username, $password)
144155
$this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
145156
}
146157

147-
public function setHeader($key, $value)
158+
public function setHeader($key, $value = '')
148159
{
149160
$this->headers[$key] = $key . ': ' . $value;
150161
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->headers));

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,16 @@ public function testCookieJar() {
278278
}
279279

280280
public function testMultipleCookieResponse() {
281+
$expected_response = 'cookie1=scrumptious,cookie2=mouthwatering';
282+
283+
// github.com/facebook/hhvm/issues/2345
284+
if (defined('HHVM_VERSION')) {
285+
$expected_response = 'cookie2=mouthwatering,cookie1=scrumptious';
286+
}
287+
281288
$test = new Test();
282289
$test->server('multiple_cookie', 'GET');
283-
$this->assertEquals($test->curl->response_headers['Set-Cookie'], 'cookie1=scrumptious,cookie2=mouthwatering');
290+
$this->assertEquals($test->curl->response_headers['Set-Cookie'], $expected_response);
284291
}
285292

286293
public function testError() {
@@ -295,7 +302,13 @@ public function testError() {
295302
public function testErrorMessage() {
296303
$test = new Test();
297304
$test->server('error_message', 'GET');
298-
$this->assertTrue($test->curl->error_message === 'HTTP/1.1 401 Unauthorized');
305+
306+
$expected_response = 'HTTP/1.1 401 Unauthorized';
307+
if (defined('HHVM_VERSION')) {
308+
$expected_response = 'HTTP/1.1 401';
309+
}
310+
311+
$this->assertEquals($test->curl->error_message, $expected_response);
299312
}
300313

301314
public function testHeaders() {

0 commit comments

Comments
 (0)