Do not save temporary redirect URLs

Created on 20 July 2018, over 6 years ago
Updated 10 September 2023, over 1 year ago

Problem/Motivation

When aggregator fetches a feed and hits a redirect, it updates the feed URL so that it will visit the new URL in the future. This is good in many cases, but not all.

It's a problem for me because servers that host our feeds occasionally go down for maintenance, and when they do, they temporarily redirect all requests (including feeds) to a maintenance landing page.

This causes aggregator to update our feed URLs to the maintenance page, thus breaking the feeds.

Proposed resolution

The URL update happens in the fetch() function. The code comment claims that the URL gets updated 301 (permanent) redirects, which would make sense. But in reality, it gets updated for ALL redirects, because it only checks if the URL has changed, and does not check the actual HTTP status code:

// Update the feed URL in case of a 301 redirect.
if ($actual_uri && $actual_uri !== $feed->getUrl()) {
  $feed->setUrl($actual_uri);
}

I've attached a patch that adds a check for the HTTP status code. It will only update the URL for 301 & 308 redirects, so that temporary redirects (302, 307..) won't break our feeds:

// Update the feed URL in case of a 301 or 308 (permanent) redirect.
// Do not update the URL for temporary redirects (302, 307, etc).
if ($actual_uri && $actual_uri !== $feed->getUrl()) {
  if ($response->getStatusCode() == 301 || $response->getStatusCode() == 308) {
    $feed->setUrl($actual_uri);
  }
}

Remaining tasks

- Reviews/feedback needed. What do you think of this solution?
- Will this need a backport to D7?
- Do tests need to be written?

User interface/API/Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ivagold Philadelphia, PA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024