remove vestigial code pieces and make usage clearer for Scholar.Utilities.HTTP

This commit is contained in:
Simon Kornblith 2006-06-26 16:32:19 +00:00
parent ed47e0c84c
commit cb647aa607

View file

@ -968,8 +968,15 @@ Scholar.Utilities.HTTP = new function() {
* Send an HTTP GET request via XMLHTTPRequest * Send an HTTP GET request via XMLHTTPRequest
* *
* Returns false if browser is offline * Returns false if browser is offline
*
* doGet can be called as:
* Scholar.Utilities.HTTP.doGet(url, onDone)
* Scholar.Utilities.HTTP.doGet(url, onStatus, onDone)
*
* The status handler, which doesn't really serve a very noticeable purpose
* in our code, is required for compatiblity with the Piggy Bank project
**/ **/
function doGet(url, onStatus, onDone) { function doGet(url, callback1, callback2) {
if (this.browserIsOffline()){ if (this.browserIsOffline()){
return false; return false;
} }
@ -980,7 +987,7 @@ Scholar.Utilities.HTTP = new function() {
var test = xmlhttp.open('GET', url, true); var test = xmlhttp.open('GET', url, true);
xmlhttp.onreadystatechange = function(){ xmlhttp.onreadystatechange = function(){
_stateChange(xmlhttp, onStatus, onDone); _stateChange(xmlhttp, callback1, callback2);
}; };
xmlhttp.send(null); xmlhttp.send(null);
@ -993,23 +1000,26 @@ Scholar.Utilities.HTTP = new function() {
* Send an HTTP POST request via XMLHTTPRequest * Send an HTTP POST request via XMLHTTPRequest
* *
* Returns false if browser is offline * Returns false if browser is offline
*
* doPost can be called as:
* Scholar.Utilities.HTTP.doPost(url, body, onDone)
* Scholar.Utilities.HTTP.doPost(url, body, onStatus, onDone)
*
* The status handler, which doesn't really serve a very noticeable purpose
* in our code, is required for compatiblity with the Piggy Bank project
**/ **/
function doPost(url, body, onStatus, onDone) { function doPost(url, body, callback1, callback2) {
if (this.browserIsOffline()){ if (this.browserIsOffline()){
return false; return false;
} }
if(this.proxiedURL) {
url = Scholar.Ingester.ProxyMonitor.properToProxy(url);
}
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(); .createInstance();
xmlhttp.open('POST', url, true); xmlhttp.open('POST', url, true);
var me = this;
xmlhttp.onreadystatechange = function(){ xmlhttp.onreadystatechange = function(){
_stateChange(xmlhttp, onStatus, onDone); _stateChange(xmlhttp, callback1, callback2);
}; };
xmlhttp.send(body); xmlhttp.send(body);
@ -1021,24 +1031,25 @@ Scholar.Utilities.HTTP = new function() {
/** /**
* Send an HTTP OPTIONS request via XMLHTTPRequest * Send an HTTP OPTIONS request via XMLHTTPRequest
* *
* Returns false if browser is offline * doOptions can be called as:
* Scholar.Utilities.HTTP.doOptions(url, body, onDone)
* Scholar.Utilities.HTTP.doOptions(url, body, onStatus, onDone)
*
* The status handler, which doesn't really serve a very noticeable purpose
* in our code, is required for compatiblity with the Piggy Bank project
**/ **/
function doOptions(url, body, onStatus, onDone) { function doOptions(url, body, callback1, callback2) {
if (this.browserIsOffline()){ if (this.browserIsOffline()){
return false; return false;
} }
if(this.proxiedURL) {
url = Scholar.Ingester.ProxyMonitor.properToProxy(url);
}
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(); .createInstance();
xmlhttp.open('OPTIONS', url, true); xmlhttp.open('OPTIONS', url, true);
var me = this;
xmlhttp.onreadystatechange = function(){ xmlhttp.onreadystatechange = function(){
_stateChange(xmlhttp, onStatus, onDone); _stateChange(xmlhttp, callback1, callback2);
}; };
xmlhttp.send(body); xmlhttp.send(body);
@ -1053,10 +1064,13 @@ Scholar.Utilities.HTTP = new function() {
} }
function _stateChange(xmlhttp, onStatus, onDone){ function _stateChange(xmlhttp, callback1, callback2){
if(!onDone) { if(callback2) {
onStatus = callback1;
onDone = callback2;
} else {
onDone = callback1;
onStatus = null; onStatus = null;
onDone = onStatus;
} }
switch (xmlhttp.readyState){ switch (xmlhttp.readyState){
// Request not yet made // Request not yet made