Skip to content

Commit

Permalink
Add HTTP Basic Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
nick authored and felixge committed Apr 8, 2010
1 parent d43a67a commit 9e25b24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -87,10 +87,12 @@ Takes the path of a `file` and callback receives a JS object suitable for inline

Check `lib/dep/mime.js` for a list of recognized file types.

### couchdb.createClient([port, host])
### couchdb.createClient([port, host, user, pass])

Creates a new `couchdb.Client` for a given `port` (default: `5984`) and `host` (default: `'localhost'`). This client will queue all requests that are send through it, so ordering of requests is always guaranteed. Use multiple clients for parallel operations.

If the optional `user` and `pass` arguments are supplied, all requests will be made with HTTP Basic Authorization

### client.host

The host this client is connecting to. READ-ONLY property
Expand Down
6 changes: 5 additions & 1 deletion lib/couchdb.js
Expand Up @@ -101,7 +101,7 @@ exports.toAttachment = function(file, cb) {
})
};

exports.createClient = function(port, host) {
exports.createClient = function(port, host, user, pass) {
if (isNaN(port)) {
host = port;
port = 5984;
Expand All @@ -121,6 +121,10 @@ exports.createClient = function(port, host) {
});

couchClient._queueRequest = function(options, cb) {
if(user && pass) {
options.headers.authorization = "Basic " + base64.encode(user + ":" + pass)
}

if (options.query) {
options.path += '?'+exports.toQuery(options.query);
delete options.query;
Expand Down

0 comments on commit 9e25b24

Please sign in to comment.