From c0b6785bded1926a21a17501e7ed34f920567cdd Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Mon, 2 Jun 2014 23:04:48 +0100 Subject: [PATCH] Follow all the redirects --- data/js/tomahawk.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index a5efb28da..e73e5cfa7 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -268,6 +268,15 @@ Tomahawk.syncRequest = function (url, extraHeaders, options) { xmlHttpRequest.send(null); if (xmlHttpRequest.status == 200) { return xmlHttpRequest.responseText; + } else if (xmlHttpRequest.status == 302) { + // You know that XMLHttpRequest always follows redirects? + // Guess what: It does not always. + // + // Known: + // * If you are redirect to a different domain in QtWebkit on MacOS, + // you will have to deal with 302. + Tomahawk.syncRequest(xmlHttpRequest.getResponseHeader('Location'), + extraHeaders, options); } else { Tomahawk.log("Failed to do GET request: to: " + url); Tomahawk.log("Status Code was: " + xmlHttpRequest.status); @@ -300,6 +309,15 @@ Tomahawk.asyncRequest = function (url, callback, extraHeaders, options) { xmlHttpRequest.onreadystatechange = function () { if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) { callback.call(window, xmlHttpRequest); + } else if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 302) { + // You know that XMLHttpRequest always follows redirects? + // Guess what: It does not always. + // + // Known: + // * If you are redirect to a different domain in QtWebkit on MacOS, + // you will have to deal with 302. + Tomahawk.asyncRequest(xmlHttpRequest.getResponseHeader('Location'), + callback, extraHeaders, options); } else if (xmlHttpRequest.readyState === 4) { Tomahawk.log("Failed to do " + method + " request: to: " + url); Tomahawk.log("Status Code was: " + xmlHttpRequest.status);