Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@
meta_sources: {},
vars_sources: {},

redirects: options.redirectsHistory || [],
redirects: options._redirectsInfo || [],
time: options?.totalTimer()
};

Expand Down Expand Up @@ -1376,8 +1376,11 @@
var r = result[i];
var redirect = r.error && r.error[SYS_ERRORS.redirect];
if (typeof redirect === "string") {
log(' -- plugin redirect (by "' + r.method.pluginId + '")', redirect);
return redirect;
log(' -- plugin redirect (by "' + r.method.pluginId + '")', redirect, r.error.status);
return {
url: redirect,
status: r.error.status
};
} else if (redirect && typeof redirect !== "string") {
log(' -- skip plugin redirect, not string (by "' + r.method.pluginId + '")', redirect);
}
Expand Down Expand Up @@ -1829,16 +1832,22 @@
getResultErrorMessages(result, allResults);

// Find redirect command.
var redirect = findRedirectError(result);
if (redirect) {
var redirect_data = findRedirectError(result);
if (redirect_data && redirect_data.url) {
abortCurrentRequest();
if (!redirect.match(/^https?:\/\//)) {
redirect = urlLib.resolve(uri, redirect);
if (!redirect_data.url.match(/^https?:\/\//)) {
redirect_data.url = urlLib.resolve(uri, redirect_data.url);
}
options.redirectsCount = (options.redirectsCount || 0) + 1;
options.redirectsHistory = options.redirectsHistory || [];
options.redirectsHistory.push(uri);
run(redirect, options, cb);

if (options.debug_sources) {
options._redirectsInfo = options._redirectsInfo || [];
options._redirectsInfo.push(redirect_data);
}

run(redirect_data.url, options, cb);
aborted = true;
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/system/htmlparser/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export default {
options.maxRedirects = options2.maxRedirects; // Maybe set in prepareRequestOptions for a proxy.
}
return cacheAndRespond({
redirect: headers.location
redirect: headers.location,
status: resp.status
}, null, preventCache);
}
}
Expand Down