mirror of
https://github.com/zotero/zotero.git
synced 2026-10-03 02:21:49 +00:00
HTTP.request(): Return proper status for canceled redirect
This commit is contained in:
parent
a46ed574bf
commit
cf44d4333d
1 changed files with 17 additions and 9 deletions
|
|
@ -462,13 +462,14 @@ Zotero.HTTP = new function() {
|
|||
clearTimeout(inactivityTimerID);
|
||||
|
||||
var status = redirectStatus || xmlhttp.status;
|
||||
var success;
|
||||
|
||||
try {
|
||||
if (!status) {
|
||||
let responseStatus = xmlhttp.channel.responseStatus;
|
||||
// If we cancelled a redirect, get the 3xx status from the channel
|
||||
if (responseStatus >= 300 && responseStatus < 400) {
|
||||
status = responseStatus;
|
||||
status = redirectStatus = responseStatus;
|
||||
}
|
||||
// If an invalid HTTP response includes a 4xx or 5xx HTTP response code, swap it
|
||||
// in, since it might be enough info to do what we need (e.g., verify a 404 from
|
||||
|
|
@ -488,17 +489,27 @@ Zotero.HTTP = new function() {
|
|||
catch (e) {}
|
||||
|
||||
if (options.successCodes) {
|
||||
var success = options.successCodes.indexOf(status) != -1;
|
||||
success = options.successCodes.indexOf(status) != -1;
|
||||
}
|
||||
// Explicit FALSE means allow any status code
|
||||
else if (options.successCodes === false) {
|
||||
var success = true;
|
||||
success = true;
|
||||
}
|
||||
// If we got a redirect and didn't follow it, consider that a success
|
||||
else if (options.followRedirects === false && redirectStatus) {
|
||||
success = true;
|
||||
}
|
||||
else if(isFile) {
|
||||
var success = status == 200 || status == 0;
|
||||
success = status == 200 || status == 0;
|
||||
}
|
||||
else if (redirectStatus) {
|
||||
var success = true;
|
||||
else {
|
||||
success = status >= 200 && status < 300;
|
||||
}
|
||||
|
||||
// Create a fake XMLHttpRequest object for an unfollowed or canceled redirect, since
|
||||
// the real one won't be accurate. Only `status` and `getResponseHeader('Location')`
|
||||
// are available.
|
||||
if (redirectStatus) {
|
||||
let channel = xmlhttp.channel;
|
||||
xmlhttp = {
|
||||
status,
|
||||
|
|
@ -512,9 +523,6 @@ Zotero.HTTP = new function() {
|
|||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
var success = status >= 200 && status < 300;
|
||||
}
|
||||
|
||||
if(success) {
|
||||
Zotero.debug("HTTP " + method + " " + dispURL
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue