Changeset 39
- Timestamp:
- 04/08/06 13:47:20 (3 years ago)
- Files:
-
- trunk/overhaul_headers.js (modified) (1 diff)
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 // 18 var 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 // 4 31 subject = subject.QueryInterface(Components.interfaces.nsIHttpChannel); 5 32 subject.setRequestHeader("Supports", "Overhaul 50 5000", false); 6 33 } 7 34 } 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 // 45 var httpResponseReader = { 9 46 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 // 11 55 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. 17 69 } 18 70 }; 19 71 72 73 74 //************************************** 75 //* Main script body - Executed on load 76 //************************************** 77 78 // 79 // Get the observer service 80 // 20 81 var observerService = Components.classes["@mozilla.org/observer-service;1"] 21 82 .getService(Components.interfaces.nsIObserverService); 22 23 observerService.addObserver(httpResponseObserver,"http-on-examine-response",false);24 83 84 // 85 // Register request headers injector and response 86 // reader observer objects. 87 // 88 observerService.addObserver(httpRequestInjector, "http-on-modify-request", 89 false); 90 observerService.addObserver(httpResponseReader, "http-on-examine-response", 91 false);
