From c45ae758b8d9958676432eb0c0691ff07371344b Mon Sep 17 00:00:00 2001 From: Abraham Arango Date: Sun, 4 Dec 2022 21:58:31 -0500 Subject: [PATCH 1/3] Grab status code from response with only one HTTP version number Currently, the regex is looking for HTTP version formats with major and minor versions. ``` HTTP/1.1 200 OK ``` This adds functionality to also grab status codes with only a major HTTP version like below ``` HTTP/2 400 ``` --- src/Facebook/Http/GraphRawResponse.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Facebook/Http/GraphRawResponse.php b/src/Facebook/Http/GraphRawResponse.php index 324a94472..21ed94635 100644 --- a/src/Facebook/Http/GraphRawResponse.php +++ b/src/Facebook/Http/GraphRawResponse.php @@ -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]; } From 0cec20d399f3a861a3f676ac9bcb740d070f58de Mon Sep 17 00:00:00 2001 From: Abraham Arango Date: Sun, 4 Dec 2022 22:05:13 -0500 Subject: [PATCH 2/3] Update tests to check for single HTTP version value --- tests/Http/GraphRawResponseTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Http/GraphRawResponseTest.php b/tests/Http/GraphRawResponseTest.php index aca6ba8de..5b710b9b7 100644 --- a/tests/Http/GraphRawResponseTest.php +++ b/tests/Http/GraphRawResponseTest.php @@ -47,6 +47,24 @@ class GraphRawResponseTest extends \PHPUnit_Framework_TestCase 'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=', 'Access-Control-Allow-Origin' => '*', ]; + + protected $fakeRawHeaderVersion2 = <<
'"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() { @@ -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); + } } From a34dedaa28a726ea444b0ddc45447935a6bb5a07 Mon Sep 17 00:00:00 2001 From: Abraham Arango Date: Sun, 4 Dec 2022 22:05:55 -0500 Subject: [PATCH 3/3] Fix test --- tests/Http/GraphRawResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Http/GraphRawResponseTest.php b/tests/Http/GraphRawResponseTest.php index 5b710b9b7..b4b52c8fc 100644 --- a/tests/Http/GraphRawResponseTest.php +++ b/tests/Http/GraphRawResponseTest.php @@ -100,7 +100,7 @@ public function testWillIgnoreProxyHeaders() public function testCanSetTheHeadersFromAStringWithVersionTwo() { - $response = new GraphRawResponse($this->$fakeRawHeaderVersion2, ''); + $response = new GraphRawResponse($this->fakeRawHeaderVersion2, ''); $headers = $response->getHeaders(); $httpResponseCode = $response->getHttpResponseCode();