mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Follow all the redirects
This commit is contained in:
@@ -268,6 +268,15 @@ Tomahawk.syncRequest = function (url, extraHeaders, options) {
|
|||||||
xmlHttpRequest.send(null);
|
xmlHttpRequest.send(null);
|
||||||
if (xmlHttpRequest.status == 200) {
|
if (xmlHttpRequest.status == 200) {
|
||||||
return xmlHttpRequest.responseText;
|
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 {
|
} else {
|
||||||
Tomahawk.log("Failed to do GET request: to: " + url);
|
Tomahawk.log("Failed to do GET request: to: " + url);
|
||||||
Tomahawk.log("Status Code was: " + xmlHttpRequest.status);
|
Tomahawk.log("Status Code was: " + xmlHttpRequest.status);
|
||||||
@@ -300,6 +309,15 @@ Tomahawk.asyncRequest = function (url, callback, extraHeaders, options) {
|
|||||||
xmlHttpRequest.onreadystatechange = function () {
|
xmlHttpRequest.onreadystatechange = function () {
|
||||||
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
|
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
|
||||||
callback.call(window, xmlHttpRequest);
|
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) {
|
} else if (xmlHttpRequest.readyState === 4) {
|
||||||
Tomahawk.log("Failed to do " + method + " request: to: " + url);
|
Tomahawk.log("Failed to do " + method + " request: to: " + url);
|
||||||
Tomahawk.log("Status Code was: " + xmlHttpRequest.status);
|
Tomahawk.log("Status Code was: " + xmlHttpRequest.status);
|
||||||
|
Reference in New Issue
Block a user