Skip to content

Commit a5e2b42

Browse files
authored
debug: store redirects and redirect status code (#597)
1 parent 03f44f9 commit a5e2b42

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lib/core.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@
11041104
meta_sources: {},
11051105
vars_sources: {},
11061106

1107-
redirects: options.redirectsHistory || [],
1107+
redirects: options._redirectsInfo || [],
11081108
time: options?.totalTimer()
11091109
};
11101110

@@ -1376,8 +1376,11 @@
13761376
var r = result[i];
13771377
var redirect = r.error && r.error[SYS_ERRORS.redirect];
13781378
if (typeof redirect === "string") {
1379-
log(' -- plugin redirect (by "' + r.method.pluginId + '")', redirect);
1380-
return redirect;
1379+
log(' -- plugin redirect (by "' + r.method.pluginId + '")', redirect, r.error.status);
1380+
return {
1381+
url: redirect,
1382+
status: r.error.status
1383+
};
13811384
} else if (redirect && typeof redirect !== "string") {
13821385
log(' -- skip plugin redirect, not string (by "' + r.method.pluginId + '")', redirect);
13831386
}
@@ -1829,16 +1832,22 @@
18291832
getResultErrorMessages(result, allResults);
18301833

18311834
// Find redirect command.
1832-
var redirect = findRedirectError(result);
1833-
if (redirect) {
1835+
var redirect_data = findRedirectError(result);
1836+
if (redirect_data && redirect_data.url) {
18341837
abortCurrentRequest();
1835-
if (!redirect.match(/^https?:\/\//)) {
1836-
redirect = urlLib.resolve(uri, redirect);
1838+
if (!redirect_data.url.match(/^https?:\/\//)) {
1839+
redirect_data.url = urlLib.resolve(uri, redirect_data.url);
18371840
}
18381841
options.redirectsCount = (options.redirectsCount || 0) + 1;
18391842
options.redirectsHistory = options.redirectsHistory || [];
18401843
options.redirectsHistory.push(uri);
1841-
run(redirect, options, cb);
1844+
1845+
if (options.debug_sources) {
1846+
options._redirectsInfo = options._redirectsInfo || [];
1847+
options._redirectsInfo.push(redirect_data);
1848+
}
1849+
1850+
run(redirect_data.url, options, cb);
18421851
aborted = true;
18431852
return;
18441853
}

lib/plugins/system/htmlparser/htmlparser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export default {
132132
options.maxRedirects = options2.maxRedirects; // Maybe set in prepareRequestOptions for a proxy.
133133
}
134134
return cacheAndRespond({
135-
redirect: headers.location
135+
redirect: headers.location,
136+
status: resp.status
136137
}, null, preventCache);
137138
}
138139
}

0 commit comments

Comments
 (0)