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

Commit 2392804

Browse files
authored
Merge pull request #1079 from bytestream/5.6
Fix #1076
2 parents 674b2b5 + 60847fd commit 2392804

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
99
- 5.7.0 (2018-00-00)
1010
- Add `joined` to list of fields to be cast to `\DateTime` (#950)
1111
- Add `GraphPage::getFanCount()` to get the number of people who like the page (#815)
12+
- Fixed HTTP/2 support (#1079)
1213
- 5.6.3 (2018-07-01)
1314
- Add fix for countable error in PHP 7.2 (originally #969 by @andreybolonin)
1415
- 5.6.2 (2018-02-15)

src/Facebook/Http/GraphRawResponse.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ public function getHttpResponseCode()
104104
*/
105105
public function setHttpResponseCodeFromHeader($rawResponseHeader)
106106
{
107-
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);
108-
$this->httpResponseCode = (int)$match[1];
107+
// https://tools.ietf.org/html/rfc7230#section-3.1.2
108+
list($version, $status, $reason) = array_pad(explode(' ', $rawResponseHeader, 3), 3, null);
109+
$this->httpResponseCode = (int) $status;
109110
}
110111

111112
/**

tests/Http/GraphRawResponseTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,21 @@ public function testCanTransformJsonHeaderValues()
9090

9191
$this->assertEquals($this->jsonFakeHeaderAsArray['x-fb-ads-insights-throttle'], $headers['x-fb-ads-insights-throttle']);
9292
}
93+
94+
public function testHttpResponseCode()
95+
{
96+
// HTTP/1.0
97+
$headers = str_replace('HTTP/1.1', 'HTTP/1.0', $this->fakeRawHeader);
98+
$response = new GraphRawResponse($headers, '');
99+
$this->assertEquals(200, $response->getHttpResponseCode());
100+
101+
// HTTP/1.1
102+
$response = new GraphRawResponse($this->fakeRawHeader, '');
103+
$this->assertEquals(200, $response->getHttpResponseCode());
104+
105+
// HTTP/2
106+
$headers = str_replace('HTTP/1.1', 'HTTP/2', $this->fakeRawHeader);
107+
$response = new GraphRawResponse($headers, '');
108+
$this->assertEquals(200, $response->getHttpResponseCode());
109+
}
93110
}

0 commit comments

Comments
 (0)