fix: Recursively follow redirects for feeds, fixes #2774

pull/2997/head
iglocska 2018-01-08 15:56:13 +01:00
parent 115f7d4592
commit a5ceed1522
1 changed files with 12 additions and 5 deletions

View File

@ -183,6 +183,16 @@ class Feed extends AppModel {
return $events;
}
private function __getRecursive($url, $query, $request, $iterations = 0) {
if ($iterations == 5) return false;
$HttpSocket = $this->__setupHttpSocket(false);
$response = $HttpSocket->get($url, $query, $request);
if ($response->code == 302 || $response->code == 301) {
$response = $this->__getRecursive($response['header']['Location'], $query, $request, $iterations + 1);
}
return $response;
}
public function getFreetextFeed($feed, $HttpSocket, $type = 'freetext', $page = 1, $limit = 60, &$params = array()) {
$result = array();
$data = '';
@ -203,14 +213,11 @@ class Feed extends AppModel {
if ($doFetch) {
$fetchIssue = false;
try {
$response = $HttpSocket->get($feed['Feed']['url'], '', array());
$response = $this->__getRecursive($feed['Feed']['url'], '', array());
//$response = $HttpSocket->get($feed['Feed']['url'], '', array());
} catch (Exception $e) {
return false;
}
if ($response->code == 302) {
$HttpSocket = $this->__setupHttpSocket(false);
$response = $HttpSocket->get($response['header']['Location'], '', array());
}
if ($response->code == 200) {
$redis = $this->setupRedis();
if ($redis === false) {