From 0e43c3e5087dbe7cc43087fc0105d1575b5de251 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 2 Apr 2022 11:41:15 +0200 Subject: [PATCH] Upgrade feed url to https if possible --- .../core/service/download/HttpDownloader.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 01c135061..2393cedef 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -73,6 +73,10 @@ public class HttpDownloader extends Downloader { httpReq.cacheControl(new CacheControl.Builder().noCache().build()); // noStore breaks CDNs } + if (uri.getScheme().equals("http")) { + httpReq.addHeader("Upgrade-Insecure-Requests", "1"); + } + if (!TextUtils.isEmpty(request.getLastModified())) { String lastModified = request.getLastModified(); Date lastModifiedDate = DateUtils.parse(lastModified); @@ -284,15 +288,19 @@ public class HttpDownloader extends Downloader { responses.add(response); response = response.priorResponse(); } - if (responses.isEmpty()) { + if (responses.size() < 2) { return; } Collections.reverse(responses); int firstCode = responses.get(0).code(); + String firstUrl = responses.get(0).request().url().toString(); + String secondUrl = responses.get(1).request().url().toString(); if (firstCode == HttpURLConnection.HTTP_MOVED_PERM || firstCode == StatusLine.HTTP_PERM_REDIRECT) { - String secondUrl = responses.get(1).request().url().toString(); Log.d(TAG, "Detected permanent redirect from " + request.getSource() + " to " + secondUrl); permanentRedirectUrl = secondUrl; + } else if (secondUrl.equals(firstUrl.replace("http://", "https://"))) { + Log.d(TAG, "Treating http->https non-permanent redirect as permanent: " + firstUrl); + permanentRedirectUrl = secondUrl; } }