Skip to content

Commit

Permalink
Using builtin base64.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Aug 12, 2010
1 parent 09e7ade commit cec3f3f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var http = require('http'),
url = require('url'),
sys = require('sys'),
base64 = require('./base64');
var http = require('http')
, url = require('url')
, sys = require('sys')
;

var toBase64 = function(str) {
return (new Buffer(str || "", "ascii")).toString("base64");
};

function request (options, callback) {
if (!options.uri) {
Expand Down Expand Up @@ -49,12 +53,12 @@ function request (options, callback) {

var clientErrorHandler = function (error) {
if (setHost) delete options.headers.host;
callback(error);
if (callback) callback(error);
}
options.client.addListener('error', clientErrorHandler);

if (options.uri.auth && !options.headers.authorization) {
options.headers.authorization = "Basic " + base64.encode(options.uri.auth);
options.headers.authorization = "Basic " + toBase64(options.uri.auth);
}
options.fullpath = options.uri.href.replace(options.uri.protocol + '//' + options.uri.host, '');
if (options.fullpath.length === 0) options.fullpath = '/'
Expand Down Expand Up @@ -86,7 +90,7 @@ function request (options, callback) {
}

if (setHost) delete options.headers.host;
callback(null, response, buffer);
if (callback) callback(null, response, buffer);
})
})

Expand Down

0 comments on commit cec3f3f

Please sign in to comment.