Permalink
Browse files

Inconsequential style review.

  • Loading branch information...
1 parent ef85b73 commit 76227c51391b617c0b8f0c779bef74038d24823b @kriskowal kriskowal committed Mar 1, 2010
Showing with 20 additions and 4 deletions.
  1. +8 −3 engines/default/lib/system.js
  2. +12 −1 lib/http-client.js
@@ -8,9 +8,13 @@ exports.print = function () {
exports.stdout.write(Array.prototype.join.call(arguments, ' ') + "\n").flush();
};
-exports.stdin = new IO(function(){}, null);
-exports.stdout = new IO(null, function(string) { exports.print(String(string).replace(/\n$/,"")); });
-exports.stderr = new IO(null, function(string) { exports.print(String(string).replace(/\n$/,"")); });
+exports.stdin = new IO(function () {}, null);
+exports.stdout = new IO(null, function(string) {
+ exports.print(String(string).replace(/\n$/,""));
+});
+exports.stderr = new IO(null, function(string) {
+ exports.print(String(string).replace(/\n$/,""));
+});
exports.args = global.arguments || [];
@@ -21,3 +25,4 @@ exports.fs = require('./file');
// default logger
var Logger = require("logger").Logger;
exports.log = new Logger(exports.stderr);
+
View
@@ -14,6 +14,7 @@ var newTransactionId = (function () {
return id ++;
};
})();
+
var transaction = (function () {
var hidden = {};
return function (id, del) {
@@ -26,7 +27,6 @@ var transaction = (function () {
};
})();
-
// {method, url, headers, body}
// return value is {status:status, headers:{..}, body:[..]}
function HttpClient (settings) {
@@ -36,6 +36,7 @@ function HttpClient (settings) {
};
HttpClient.prototype = {
+
create : function HttpClient_create () {
// clean up, set up defaults.
transaction(this.txId, true);
@@ -47,12 +48,14 @@ HttpClient.prototype = {
});
return this;
},
+
setOptions : function HttpClient_setOption (settings) {
for (var key in settings) if (settings.hasOwnProperty(key)) {
this.setOption(key, settings[key]);
}
return this;
},
+
setOption : function HttpClient_setOption (key, val) {
var guts = transaction(this.txId);
switch (key) {
@@ -71,18 +74,21 @@ HttpClient.prototype = {
}
return this;
},
+
setHeaders : function HttpClient_setHeaders (headers) {
for (var h in headers) if (headers.hasOwnProperty(h)) {
this.setHeader(h, headers[h]);
}
return this;
},
+
setHeader : function HttpClient_setHeader (key, val) {
var guts = transaction(this.txId);
if (!guts.hasOwnProperty("headers")) guts.headers = {};
HashP.set(guts.headers, key, val);
return this;
},
+
write : function HttpClient_write (data) {
var guts = transaction(this.txId);
var len = HashP.get(guts.headers, "Content-Length") || 0;
@@ -91,14 +97,17 @@ HttpClient.prototype = {
guts.body.push(data);
return this;
},
+
connect : function HttpClient_connect (decode) {
var guts = transaction(this.txId);
var resp = engine.connect(guts);
if (decode) HttpClient.decode(resp);
transaction(this.txId, true);
return resp;
}
+
};
+
HttpClient.decode = function HttpClient_decode (resp, encoding) {
encoding = encoding || HashP.get(resp.headers, "Content-Encoding");
if (!encoding) {
@@ -119,11 +128,13 @@ HttpClient.decode = function HttpClient_decode (resp, encoding) {
}};
return resp;
};
+
HttpClient.undecode = function HttpClient_undecode (resp) {
if ("_rawBody" in resp) resp.body = resp._rawBody;
delete resp._rawBody;
return resp;
};
+
HttpClient.print = function HttpClient_print (resp) {
var out = [];
out.push(resp.statusText);

0 comments on commit 76227c5

Please sign in to comment.