Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/Facebook/Http/GraphRawResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public function getHttpResponseCode()
public function setHttpResponseCodeFromHeader($rawResponseHeader)
{
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);

if (isset($match[1])) {
$this->httpResponseCode = (int)$match[1];
}

preg_match('|HTTP/\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);

$this->httpResponseCode = (int)$match[1];
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Http/GraphRawResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ class GraphRawResponseTest extends \PHPUnit_Framework_TestCase
'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=',
'Access-Control-Allow-Origin' => '*',
];

protected $fakeRawHeaderVersion2 = <<<HEADER
HTTP/2 200 OK
Etag: "9d86b21aa74d74e574bbb35ba13524a52deb96e5"
Content-Type: text/javascript; charset=UTF-8
X-FB-Rev: 9244769
Date: Mon, 5 December 2022 18:37:17 GMT
X-FB-Debug: 02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=
Access-Control-Allow-Origin: *\r\n\r\n
HEADER;
protected $fakeHeadersAsArrayVersion2 = [
'Etag' => '"9d86b21aa74d74e574bbb35ba13524a52deb96e5"',
'Content-Type' => 'text/javascript; charset=UTF-8',
'X-FB-Rev' => '9244769',
'Date' => 'Mon, 5 December 2022 18:37:17 GMT',
'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=',
'Access-Control-Allow-Origin' => '*',
];

public function testCanSetTheHeadersFromAnArray()
{
Expand Down Expand Up @@ -79,4 +97,14 @@ public function testWillIgnoreProxyHeaders()
$this->assertEquals($this->fakeHeadersAsArray, $headers);
$this->assertEquals(200, $httpResponseCode);
}

public function testCanSetTheHeadersFromAStringWithVersionTwo()
{
$response = new GraphRawResponse($this->fakeRawHeaderVersion2, '');
$headers = $response->getHeaders();
$httpResponseCode = $response->getHttpResponseCode();

$this->assertEquals($this->fakeHeadersAsArrayVersion2, $headers);
$this->assertEquals(200, $httpResponseCode);
}
}