Skip to content

Commit

Permalink
Removed minResponses and minContentLength from config options and det…
Browse files Browse the repository at this point in the history
…ermine them dynamically based on the first and second responses.
  • Loading branch information
richard-flosi committed Sep 3, 2013
1 parent 3482ce6 commit 97285b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions bin/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"verbose": true,
"debug": false,
"minResponses": 5,
"minContentLength": 4000,
"checkCompleteInterval": 10,
"checkCompleteTimeDiff": 300,
"checkCompleteTimeout": 10000
Expand Down
12 changes: 10 additions & 2 deletions lib/phantom-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var page = require('webpage').create(),
requestCount = 0,
responseCount = 0,
requestIds = [],
minContentLength,
minResponses,
checkComplete,
checkCompleteInterval;

Expand All @@ -31,6 +33,12 @@ page.onResourceReceived = function(response) {
response.redirectURL
);
}
if (response.id === 1) { // first response
minContentLength = response.bodySize;
}
if (responseCount === 1) { // second response
minResponses = requestCount;
}
lastReceived = new Date().getTime();
responseCount++;
requestIds[requestIds.indexOf(response.id)] = null;
Expand All @@ -39,8 +47,8 @@ page.onResourceReceived = function(response) {

checkComplete = function () {
var timeDiff = new Date().getTime() - lastReceived;
if (responseCount >= config.minResponses &&
page.content.length >= config.minContentLength &&
if (responseCount >= minResponses &&
page.content.length >= minContentLength &&
timeDiff > config.checkCompleteTimeDiff &&
requestCount === responseCount) {
clearInterval(checkCompleteInterval);
Expand Down

0 comments on commit 97285b9

Please sign in to comment.