diff --git a/lib/XRay/Fetcher.php b/lib/XRay/Fetcher.php index 93a9891..1af5fc4 100644 --- a/lib/XRay/Fetcher.php +++ b/lib/XRay/Fetcher.php @@ -89,9 +89,17 @@ class Fetcher { // Show an error if the content type returned is not a recognized type $format = null; - if(isset($result['headers']['Content-Type']) && is_string($result['headers']['Content-Type'])) { - $type = new MediaType($result['headers']['Content-Type']); - $format = $type->format; + if(isset($result['headers']['Content-Type'])) { + $contentType = null; + if(is_array($result['headers']['Content-Type'])) { + $contentType = $result['headers']['Content-Type'][0]; + } elseif(is_string($result['headers']['Content-Type'])) { + $contentType = $result['headers']['Content-Type']; + } + if($contentType) { + $type = new MediaType($contentType); + $format = $type->format; + } } if(!$format || diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 9039633..474c388 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -940,4 +940,15 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals('XRay should use this content since the JSON in the rel-alternate is invalid', $data['data']['content']['text']); } + public function testMultipleContentTypeHeaders() { + $url = 'http://source.example.com/multiple-content-type'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('mf2+html', $data['source-format']); + } + } diff --git a/tests/data/source.example.com/multiple-content-type b/tests/data/source.example.com/multiple-content-type new file mode 100644 index 0000000..8e45719 --- /dev/null +++ b/tests/data/source.example.com/multiple-content-type @@ -0,0 +1,15 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 +Content-Type: text/html +Connection: keep-alive + + + + Test + + +

This page has a link to target.example.com and some formatted text but is in a p-content element so is plaintext.

+ +