Skip to content

Integration for HHVM Support #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ php:
- '5.6'
- '7.0'
- '7.1'
# - hhvm # on Trusty only
- hhvm # on Trusty only
# - nightly

cache:
Expand All @@ -18,6 +18,8 @@ matrix:
include:
- php: '5.6'
env: STREAM_CLIENT_ONLY=1
- php: hhvm
env: STREAM_CLIENT_ONLY=1

before_install:
- nvm install 6.11
Expand Down
26 changes: 24 additions & 2 deletions src/Parse/HttpClients/ParseStreamHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ public function send($url, $method = 'GET', $data = array())
if ($method == "GET") {
// handle GET
$query = http_build_query($data, null, '&');
$this->options['http']['content'] = $query;

if (!defined('HHVM_VERSION')) {
$this->options['http']['content'] = $query;
} else {
// HHVM doesn't reapply 'content' to the url
// have to do it ourselves
$url.='?'.$query;
}

$this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded');
} elseif ($method == "POST") {
// handle POST
Expand All @@ -221,7 +229,21 @@ public function send($url, $method = 'GET', $data = array())
}

// set headers
$this->options['http']['header'] = $this->buildRequestHeaders();
if (!defined('HHVM_VERSION')) {
// default
$this->options['http']['header'] = $this->buildRequestHeaders();
} else {
/**
* HHVM bug bypass
* Passing via 'header' ends up duplicating all custom headers submitted due to a bug in HHVM.
* We can bypass this through the separate 'user_agent' field, as it is never sanitized,
* so we can append our desired headers after the initial user-agent string.
* Note that this works in php5 as well (probably 7 and up too),
* but for now we use this only where we need it.
* Source: https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/http-stream-wrapper.cpp#L92
*/
$this->options['http']['user_agent'] = "parse-php-sdk\r\n".$this->buildRequestHeaders();
}

// create a stream context
$this->parseStream->createContext($this->options);
Expand Down
2 changes: 1 addition & 1 deletion src/Parse/ParsePolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setCoordinates($coords)
}
$points = [];
foreach ($coords as $coord) {
$geoPoint;
$geoPoint = null;
if ($coord instanceof ParseGeoPoint) {
$geoPoint = $coord;
} elseif (is_array($coord) && count($coord) === 2) {
Expand Down
5 changes: 4 additions & 1 deletion tests/Parse/ParseStreamHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

class ParseStreamHttpClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @group test-get-response
*/
public function testGetResponse()
{
$client = new ParseStreamHttpClient();
Expand All @@ -25,7 +28,7 @@ public function testGetResponse()
// get response headers
$headers = $client->getResponseHeaders();

$this->assertEquals('HTTP/1.0 200 OK', $headers['http_code']);
$this->assertTrue(preg_match('|HTTP/1\.\d\s200\sOK|', $headers['http_code']) === 1);
}

public function testInvalidUrl()
Expand Down