From 7ca88a6e18a5d9f6936dc028411038c4e1af0438 Mon Sep 17 00:00:00 2001 From: Elbert Alias Date: Sun, 9 Feb 2014 13:49:36 +1100 Subject: [PATCH] Analyse headers --- drivers/firefox-sdk/lib/driver.js | 56 ++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/firefox-sdk/lib/driver.js b/drivers/firefox-sdk/lib/driver.js index a798aa451..02c88980a 100644 --- a/drivers/firefox-sdk/lib/driver.js +++ b/drivers/firefox-sdk/lib/driver.js @@ -2,9 +2,11 @@ 'use strict'; var + {Cc, Ci} = require('chrome'), main = require('wappalyzer'), w = main.wappalyzer, tabCache = {}, + headersCache = {}, categoryNames = {}, data = require('sdk/self').data, tabs = require('sdk/tabs'), @@ -42,6 +44,10 @@ }); worker.port.on('analyze', function(message) { + if ( headersCache[tab.url] !== undefined ) { + message.analyze.headers = headersCache[tab.url]; + } + w.analyze(message.hostname, message.url, message.analyze); }); @@ -83,6 +89,40 @@ analyzed: [] }; } + + var httpRequestObserver = { + init: function() { + var observerService = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService); + + observerService.addObserver(this, 'http-on-examine-response', false); + }, + + observe: function(subject, topic, data) { + if ( topic == 'http-on-examine-response' ) { + subject.QueryInterface(Ci.nsIHttpChannel); + + this.onExamineResponse(subject); + } + }, + + onExamineResponse: function (subject) { + if ( headersCache.length > 50 ) { + headersCache = {}; + } + + if ( subject.contentType === 'text/html' ) { + if ( headersCache[subject.URI.spec] === undefined ) { + headersCache[subject.URI.spec] = {}; + } + + subject.visitResponseHeaders(function(header, value) { + headersCache[subject.URI.spec][header.toLowerCase()] = value; + }); + } + } + }; + + httpRequestObserver.init(); }, displayApps: function() { @@ -118,7 +158,21 @@ }, ping: function() { - w.log('ping'); + var Request = require('sdk/request').Request; + + if ( Object.keys(w.ping.hostnames).length ) { + Request({ + url: w.config.websiteURL + 'ping/v2/', + content: { json: encodeURIComponent(JSON.stringify(w.ping)) }, + onComplete: function (response) { + w.log('w.driver.ping: status ' + response.status); + } + }).post(); + + w.log('w.driver.ping: ' + JSON.stringify(w.ping)); + + w.ping = { hostnames: {} }; + } }, categoryOrder: [ // Used to pick the main application