Changeset 39

Show
Ignore:
Timestamp:
04/08/06 13:47:20 (3 years ago)
Author:
atack2
Message:

Completed the outgoing header injector and the incoming response reader. This will end up being the central point of operations for overhaul behavior. In particular, see the httpResponseReader object; there is a note there for where overhaul behavior should be specified.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/overhaul_headers.js

    r36 r39  
    1 myDump("Headers were included!"); 
    2 var sendHeadersObserver = {  
    3         observe: function(subject,topic,data){ 
     1//* 
     2//* Herein are the necessary observers and functions to initiate 
     3//* overhaul behavior on the client.  Methods from other sources 
     4//* shall be referenced and called from within this script.  In 
     5//* particular, to control overhaul behavior, see the 
     6//* httpResponseReader object. 
     7//* 
     8 
     9 
     10 
     11// 
     12// An observer which njects an overhaul support header with  
     13// outgoing headers, on any outgoing request. 
     14// 
     15// IMPLEMENTS: nsIObserver 
     16// OBSERVES: http-on-modify-request 
     17// 
     18var httpRequestInjector = {  
     19        observe: function(subject,topic,data)   { 
     20                // 
     21                // Make sure we observe the event we think we should. 
     22                // 
     23                if ( topic != "http-on-modify-request" ) 
     24                        throw "OVERHAUL ERROR: Object 'httpRequestInjector' was asked"  
     25                                + " to observe an event of type: " + topic  
     26                                + " when it only accepts type http-on-modify-request"; 
     27                 
     28                // 
     29                // Inject the "Supports: Overhaul xx xxxx" tag 
     30                // 
    431                subject = subject.QueryInterface(Components.interfaces.nsIHttpChannel); 
    532                subject.setRequestHeader("Supports", "Overhaul 50 5000", false); 
    633        } 
    734} 
    8 var httpResponseObserver = {  
     35 
     36// 
     37// An observer which examines incoming responses from the 
     38// server.  If that response indicates that we should act 
     39// in overhaul mode, this takes the appropriate actions  
     40// with the rest of the overhaul code. 
     41// 
     42// IMPLEMENTS: nsIObserver 
     43// OBSERVES: http-on-examine-response 
     44// 
     45var httpResponseReader = {  
    946        observe: function(subject,topic,data) { 
    10                 myDump("Observer starting"); 
     47                if ( topic != "http-on-examine-response" ) 
     48                        throw "OVERHAUL ERROR: Object 'httpResponseReader' was asked"  
     49                                + " to observe an event of type: " + topic  
     50                                + " when it only accepts type http-on-examine-response"; 
     51         
     52                // 
     53                // Check for an overhaul response header 
     54                // 
    1155                subject = subject.QueryInterface(Components.interfaces.nsIHttpChannel); 
    12                 //var value = subject.getResponseHeader("Overhaul-chunks"); 
    13                 var value = "hi"; 
    14                 myDump("Observing ending"); 
    15                 var message = "value is "; 
    16                 myDump(message); 
     56                try     { 
     57                        var value = subject.getResponseHeader("Overhaul-chunks"); 
     58                } 
     59                catch( e )      { 
     60                        myDump("Server did not request Overhaul."); 
     61                        return; 
     62                } 
     63                 
     64                // 
     65                // Perform Overhaul functions 
     66                // 
     67                myDump("Entering Overhaul mode..."); 
     68                // TODO Everything else. 
    1769        } 
    1870}; 
    1971 
     72 
     73 
     74//************************************** 
     75//* Main script body - Executed on load 
     76//************************************** 
     77 
     78// 
     79// Get the observer service 
     80// 
    2081var observerService = Components.classes["@mozilla.org/observer-service;1"] 
    2182        .getService(Components.interfaces.nsIObserverService); 
    22          
    23 observerService.addObserver(httpResponseObserver,"http-on-examine-response",false); 
    2483 
     84// 
     85// Register request headers injector and response 
     86// reader observer objects. 
     87// 
     88observerService.addObserver(httpRequestInjector, "http-on-modify-request",  
     89        false); 
     90observerService.addObserver(httpResponseReader, "http-on-examine-response",  
     91        false);