Do not save temporary redirect URLs
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #2987167. --> Reported by: [ivavictoria](https://www.drupal.org/user/3061533) Related to !3 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>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. </p> <p>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.</p> <p>This causes aggregator to update our feed URLs to the maintenance page, thus breaking the feeds.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>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:</p> <pre>// Update the feed URL in case of a 301 redirect.<br>if ($actual_uri &amp;&amp; $actual_uri !== $feed-&gt;getUrl()) {<br>&nbsp; $feed-&gt;setUrl($actual_uri);<br>}</pre><p>I've attached a patch that adds a check for the HTTP status code. It will only update the URL for 301 &amp; 308 redirects, so that temporary redirects (302, 307..) won't break our feeds:</p> <pre>// Update the feed URL in case of a 301 or 308 (permanent) redirect.<br>// Do not update the URL for temporary redirects (302, 307, etc).<br>if ($actual_uri &amp;&amp; $actual_uri !== $feed-&gt;getUrl()) {<br>&nbsp; if ($response-&gt;getStatusCode() == 301 || $response-&gt;getStatusCode() == 308) {<br>&nbsp;&nbsp;&nbsp; $feed-&gt;setUrl($actual_uri);<br>&nbsp; }<br>}</pre><h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>- Reviews/feedback needed. What do you think of this solution?<br> - Will this need a backport to D7?<br> - Do tests need to be written?</p> <h3 id="summary-ui-changes">User interface/API/Data model changes</h3> <p>None.</p>
issue