Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
Created July 5, 2015 11:46
Show Gist options
  • Select an option

  • Save pcolazurdo/f9a0218668940b5682c6 to your computer and use it in GitHub Desktop.

Select an option

Save pcolazurdo/f9a0218668940b5682c6 to your computer and use it in GitHub Desktop.
PhantomJS script for detecting Content-Encoding of JS resources (for httpd diagnosis)
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: netlog4.js <some URL>');
phantom.exit(1);
} else {
address = system.args[1];
page.onResourceRequested = function (req) {
};
page.onResourceReceived = function (res) {
if ( String(res.contentType).indexOf('javascript') >= 0 ) {
var condition = false;
console.log(res.url);
res.headers.forEach( function(a,b) {
if (a.name.indexOf('Encoding') >= 0) {
console.log(a.value);
if (a.value.indexOf('gzip') = -1 ) {
console.log(JSON.stringify(res));
}
}
});
console.log('Condition');
};
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
phantom.exit();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment