From 51c9142c678c681d06f4b7ea0023653a7ba0ed92 Mon Sep 17 00:00:00 2001 From: Fulton Byrne Date: Tue, 5 Jan 2016 15:47:16 -0500 Subject: [PATCH 1/2] Added logic to allow developers to utilize full request API. --- lib/cradle.js | 3 ++- package.json | 18 +++++++++++++++--- test/raw-request-test.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test/raw-request-test.js diff --git a/lib/cradle.js b/lib/cradle.js index 269f1ab..5f6a213 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -162,7 +162,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 () { }); }; diff --git a/package.json b/package.json index a5e3f09..44525d2 100644 --- a/package.json +++ b/package.json @@ -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 ", "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": { @@ -17,6 +27,8 @@ }, "devDependencies": { "async": "~0.9.0", + "proxyquire": "^1.7.3", + "sinon": "^1.17.2", "vows": "0.8.x" }, "scripts": { diff --git a/test/raw-request-test.js b/test/raw-request-test.js new file mode 100644 index 0000000..c4e4130 --- /dev/null +++ b/test/raw-request-test.js @@ -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); From efcd474ace424b8df28d97a580e906e8579df376 Mon Sep 17 00:00:00 2001 From: Fulton Byrne Date: Wed, 6 Jan 2016 11:11:09 -0500 Subject: [PATCH 2/2] Added documentation for request pass through. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4560d79..d5e16a3 100644 --- a/README.md +++ b/README.md @@ -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. + } }); ```