Browse Source

check for meta-equiv HTTP deleted

closes #16
pull/39/head
Aaron Parecki 7 years ago
parent
commit
227311faa9
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 38 additions and 0 deletions
  1. +10
    -0
      controllers/Parse.php
  2. +13
    -0
      tests/FetchTest.php
  3. +15
    -0
      tests/data/source.example.com/deleted

+ 10
- 0
controllers/Parse.php View File

@ -226,6 +226,16 @@ class Parse {
} }
} }
// Check for meta http equiv and replace the status code if present
foreach($xpath->query('//meta[@http-equiv=\'status\']') as $el) {
$equivStatus = ''.$el->getAttribute('content');
if($equivStatus && is_string($equivStatus)) {
if(preg_match('/^(\d+)/', $equivStatus, $match)) {
$result['code'] = (int)$match[1];
}
}
}
// If the URL has a fragment ID, find the DOM starting at that node and parse it instead // If the URL has a fragment ID, find the DOM starting at that node and parse it instead
$html = $result['body']; $html = $result['body'];

+ 13
- 0
tests/FetchTest.php View File

@ -103,4 +103,17 @@ class FetchTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(401, $data->code); $this->assertEquals(401, $data->code);
} }
public function testMetaEquivDeleted() {
$url = 'http://source.example.com/deleted';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
} }

+ 15
- 0
tests/data/source.example.com/deleted View File

@ -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
Connection: keep-alive
<html>
<head>
<title>Test</title>
<meta http-equiv="status" content="410 Gone" />
</head>
<body class="h-entry">
<p class="e-content">This post has been deleted.</p>
</body>
</html>

Loading…
Cancel
Save