Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1079 from bytestream/5.6
Browse files Browse the repository at this point in the history
Fix #1076
  • Loading branch information
yguedidi authored Nov 15, 2018
2 parents 674b2b5 + 60847fd commit 2392804
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
- 5.7.0 (2018-00-00)
- Add `joined` to list of fields to be cast to `\DateTime` (#950)
- Add `GraphPage::getFanCount()` to get the number of people who like the page (#815)
- Fixed HTTP/2 support (#1079)
- 5.6.3 (2018-07-01)
- Add fix for countable error in PHP 7.2 (originally #969 by @andreybolonin)
- 5.6.2 (2018-02-15)
Expand Down
5 changes: 3 additions & 2 deletions src/Facebook/Http/GraphRawResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public function getHttpResponseCode()
*/
public function setHttpResponseCodeFromHeader($rawResponseHeader)
{
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);
$this->httpResponseCode = (int)$match[1];
// https://tools.ietf.org/html/rfc7230#section-3.1.2
list($version, $status, $reason) = array_pad(explode(' ', $rawResponseHeader, 3), 3, null);
$this->httpResponseCode = (int) $status;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Http/GraphRawResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,21 @@ public function testCanTransformJsonHeaderValues()

$this->assertEquals($this->jsonFakeHeaderAsArray['x-fb-ads-insights-throttle'], $headers['x-fb-ads-insights-throttle']);
}

public function testHttpResponseCode()
{
// HTTP/1.0
$headers = str_replace('HTTP/1.1', 'HTTP/1.0', $this->fakeRawHeader);
$response = new GraphRawResponse($headers, '');
$this->assertEquals(200, $response->getHttpResponseCode());

// HTTP/1.1
$response = new GraphRawResponse($this->fakeRawHeader, '');
$this->assertEquals(200, $response->getHttpResponseCode());

// HTTP/2
$headers = str_replace('HTTP/1.1', 'HTTP/2', $this->fakeRawHeader);
$response = new GraphRawResponse($headers, '');
$this->assertEquals(200, $response->getHttpResponseCode());
}
}

0 comments on commit 2392804

Please sign in to comment.