Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
better fix to #112, needed to report all redirections, not just last one
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 15, 2014
1 parent 3eb6aa4 commit 9015f50
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,14 @@ function beforeRequestHandler(details) {
block = httpsb.blacklisted(pageURL, type, hostname);
}

// rhill 2014-01-15: Report redirects if any.
// https://github.com/gorhill/httpswitchboard/issues/112
if ( httpsb.redirectRequests[requestURL] ) {
if ( pageStats ) {
pageStats.recordRequest('main_frame', httpsb.redirectRequests[requestURL], false);
}
delete httpsb.redirectRequests[requestURL];
}

if ( pageStats ) {
pageStats.recordRequest(type, requestURL, block);
// rhill 2014-01-15: Delay logging of non-blocked top `main_frame`
// requests, in order to ensure any potential redirects is reported
// in proper chronological order.
// https://github.com/gorhill/httpswitchboard/issues/112
if ( !isWebPage || block ) {
pageStats.recordRequest(type, requestURL, block);
}
}

// Collect global stats
Expand Down Expand Up @@ -391,6 +388,7 @@ function headersReceivedHandler(details) {
if ( i >= 0 ) {
httpsb.redirectRequests[uriTools.normalizeURI(headers[i].value)] = requestURL;
}
// console.debug('headersReceivedHandler()> redirect "%s" to "%s"', requestURL, headers[i].value);
}

// rhill 2014-01-11: Auto-scope and/or auto-whitelist only when the
Expand All @@ -399,6 +397,23 @@ function headersReceivedHandler(details) {
// scope is looked-up before auto-site-scoping and/or auto-whitelisting.
// https://github.com/gorhill/httpswitchboard/issues/119
if ( details.statusLine.indexOf(' 200') > 0 ) {
// rhill 2014-01-15: Report redirects if any.
// https://github.com/gorhill/httpswitchboard/issues/112
var mainFrameStack = [requestURL];
var destinationURL = requestURL;
var sourceURL;
while ( sourceURL = httpsb.redirectRequests[destinationURL] ) {
mainFrameStack.push(sourceURL);
delete httpsb.redirectRequests[destinationURL];
destinationURL = sourceURL;
}

if ( pageStats ) {
while ( destinationURL = mainFrameStack.pop() ) {
pageStats.recordRequest('main_frame', destinationURL, false);
}
}

// rhill 2014-01-10: Auto-site scope?
if ( httpsb.userSettings.autoCreateSiteScope ) {
httpsb.autoCreateTemporarySiteScope(requestURL);
Expand Down

0 comments on commit 9015f50

Please sign in to comment.