Skip to content

Commit

Permalink
Merge pull request #299 from Freyert/request
Browse files Browse the repository at this point in the history
Added logic to allow developers to utilize full request API.
  • Loading branch information
panuhorsmalahti committed Jan 6, 2016
2 parents 599eaa2 + efcd474 commit 5e0b9ef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Cradle's API builds right on top of Node's asynch API. Every asynch method takes
new(cradle.Connection)('http://living-room.couch', 5984, {
cache: true,
raw: false,
forceSave: true
forceSave: true,
request: {
//Pass through configuration to `request` library for all requests on this connection.
}
});
```

Expand Down
3 changes: 2 additions & 1 deletion lib/cradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ cradle.Connection.prototype.rawRequest = function (options, callback) {
options.agent = this.agent;
options.uri = this._url(options.path);
delete options.path;

options = cradle.merge(this.options.request, options);

return request(options, callback || function () { });
};

Expand Down
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
"version": "0.7.0",
"description": "the high-level, caching, CouchDB library",
"url": "http://cloudhead.io/cradle",
"keywords": ["couchdb", "database", "couch"],
"keywords": [
"couchdb",
"database",
"couch"
],
"author": "Alexis Sellier <self@cloudhead.net>",
"contributors": [
{ "name": "Charlie Robbins", "email": "charlie@nodejitsu.com" },
{ "name": "Maciej Malecki", "email": "maciej@nodejitsu.com" }
{
"name": "Charlie Robbins",
"email": "charlie@nodejitsu.com"
},
{
"name": "Maciej Malecki",
"email": "maciej@nodejitsu.com"
}
],
"main": "./lib/cradle",
"dependencies": {
Expand All @@ -17,6 +27,8 @@
},
"devDependencies": {
"async": "~0.9.0",
"proxyquire": "^1.7.3",
"sinon": "^1.17.2",
"vows": "0.8.x"
},
"scripts": {
Expand Down
28 changes: 28 additions & 0 deletions test/raw-request-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var path = require('path'),
assert = require('assert'),
events = require('events'),
vows = require('vows'),
sinon = require('sinon'),
proxyquire = require('proxyquire');

var reqSpy = sinon.spy();
var cradle = proxyquire('../lib/cradle', {
request: reqSpy
});

vows.describe('cradle/raw-request').addBatch({
'Options specified in "request" are passed directly to request library': {
topic: new(cradle.Connection)({ request: { someOption: 'filler' }}),
'should pass through values to "request"': function(topic) {
var args;
var opts = {
moreOptions: 'moreFiller',
path: 'path'
};
topic.rawRequest(opts);
args = reqSpy.getCall(0).args[0];
assert(args.moreOptions, 'moreFiller');
assert(args.someOption, 'filler');
}
}
}).export(module);

0 comments on commit 5e0b9ef

Please sign in to comment.