git.iko.soy/maciek134/podphoenix
on main help sign in
fix episode fetch crashing on redirects (#24)

for some reason a 302 will also include anything that was returned in the original redirect in the body, breaking XML Signed-off-by: Maciej Sopyło <me@klh.io>

commitac9e2ae869dccdef200c208f7bc4ae62058d272e authorMaciej Sopyło <maciek134@gmail.com> dateThu 6 Apr 2023, 16:19 (4 years ago) parent9caeb6c
2 files changed+21
app/podcasts.js+12 app/ui/SearchPage.qml+9
app/podcasts.js+12
@@ -239,6 +239,18 @@ function updateEpisodes(refreshModel) {
239239 xhr[i].open("GET", url);
240240 xhr[i].onreadystatechange = function() {
241241 if (xhr[i].readyState === XMLHttpRequest.DONE) {
242+ const location = xhr[i].getResponseHeader('Location');
243+ if (location) {
244+ // for some reason a 302 will also include anything that was
245+ // returned in the original redirect in the body, breaking XML
246+ // just re-launch the request with the new location
247+ const newXhr = new XMLHttpRequest();
248+ newXhr.open("GET", location);
249+ newXhr.onreadystatechange = xhr[i].onreadystatechange;
250+ newXhr.send();
251+ xhr[i] = newXhr;
252+ return;
253+ }
242254 xhrComplete[i] = true;
243255
244256 try {
app/ui/SearchPage.qml+9
@@ -394,6 +394,15 @@ Page {
394394 xhr.open("GET", feedUrl);
395395 xhr.onreadystatechange = function() {
396396 if (xhr.readyState === XMLHttpRequest.DONE) {
397+ const location = xhr.getResponseHeader('Location');
398+ if (location) {
399+ // for some reason a 302 will also include anything that was
400+ // returned in the original redirect in the body, breaking XML
401+ // just re-launch the request with the new location
402+ getPodcastDescription(location, index);
403+ return;
404+ }
405+
397406 var e = xhr.responseXML.documentElement;
398407 for(var h = 0; h < e.childNodes.length; h++) {
399408 if(e.childNodes[h].nodeName === "channel") {