mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Update fetch commands to respect 302 redirects
Astonishingly, node.js appears to require us to do this manually…
This commit is contained in:
parent
17fbe49f2b
commit
69528093d9
@ -92,7 +92,10 @@ Command.prototype.fetchFiles = function(options) {
|
||||
return null;
|
||||
};
|
||||
|
||||
Command.prototype.fetchFile = function(url,options,callback) {
|
||||
Command.prototype.fetchFile = function(url,options,callback,redirectCount) {
|
||||
if(redirectCount > 10) {
|
||||
return callback("Error too many redirects retrieving " + url);
|
||||
}
|
||||
var self = this,
|
||||
lib = url.substr(0,8) === "https://" ? require("https") : require("http");
|
||||
lib.get(url).on("response",function(response) {
|
||||
@ -109,7 +112,11 @@ Command.prototype.fetchFile = function(url,options,callback) {
|
||||
self.processBody(Buffer.concat(data),type,options,url);
|
||||
callback(null);
|
||||
} else {
|
||||
callback("Error " + response.statusCode + " retrieving " + url)
|
||||
if(response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
|
||||
return self.fetchFile(response.headers.location,options,callback,redirectCount + 1);
|
||||
} else {
|
||||
return callback("Error " + response.statusCode + " retrieving " + url)
|
||||
}
|
||||
}
|
||||
});
|
||||
response.on("error",function(e) {
|
||||
|
Loading…
Reference in New Issue
Block a user