Loading lib/rp.js +9 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,12 @@ var request = (function () { })(); var defaultTransformations = { HEAD: function (body, response, resolveWithFullResponse) { return resolveWithFullResponse ? response : response.headers; } }; function RP$callback(err, response, body) { /* jshint validthis:true */ Loading Loading @@ -68,7 +74,7 @@ function RP$callback(err, response, body) { } else { if (isFunction(self._rp_options.transform)) { try { self._rp_resolve(self._rp_options.transform(body, response)); self._rp_resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); } catch (e) { self._rp_reject(e); } Loading Loading @@ -106,6 +112,8 @@ request.Request.prototype.init = function RP$initInterceptor(options) { options.method = options.method.toUpperCase(); } options.transform = options.transform || defaultTransformations[options.method]; self._rp_options = options; self._rp_options.simple = options.simple === false ? false : true; self._rp_options.resolveWithFullResponse = options.resolveWithFullResponse === true ? true : false; Loading test/spec/request-test.js +29 −2 Original line number Diff line number Diff line Loading @@ -110,7 +110,8 @@ describe('Request-Promise', function () { var expectedOptions = { uri: 'http://localhost:1/200', simple: true, resolveWithFullResponse: false resolveWithFullResponse: false, transform: undefined }; rp('http://localhost:1/200') Loading Loading @@ -146,7 +147,8 @@ describe('Request-Promise', function () { var expectedOptions = { uri: 'http://localhost:4000/404', simple: true, resolveWithFullResponse: false resolveWithFullResponse: false, transform: undefined }; rp('http://localhost:4000/404') Loading Loading @@ -373,6 +375,31 @@ describe('Request-Promise', function () { }); it('for HEAD by default', function () { return rp.head('http://localhost:4000/200') .then(function (transformedResponse) { expect(transformedResponse['content-type']).to.eql('text/plain'); }); }); it('but still letting to overwrite the default transform for HEAD', function () { var options = { url: 'http://localhost:4000/200', transform: function () { return 'test'; } }; return rp.head(options) .then(function (transformedResponse) { expect(transformedResponse).to.eql('test'); }); }); }); describe('should cover the HTTP method shortcuts', function () { Loading Loading
lib/rp.js +9 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,12 @@ var request = (function () { })(); var defaultTransformations = { HEAD: function (body, response, resolveWithFullResponse) { return resolveWithFullResponse ? response : response.headers; } }; function RP$callback(err, response, body) { /* jshint validthis:true */ Loading Loading @@ -68,7 +74,7 @@ function RP$callback(err, response, body) { } else { if (isFunction(self._rp_options.transform)) { try { self._rp_resolve(self._rp_options.transform(body, response)); self._rp_resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); } catch (e) { self._rp_reject(e); } Loading Loading @@ -106,6 +112,8 @@ request.Request.prototype.init = function RP$initInterceptor(options) { options.method = options.method.toUpperCase(); } options.transform = options.transform || defaultTransformations[options.method]; self._rp_options = options; self._rp_options.simple = options.simple === false ? false : true; self._rp_options.resolveWithFullResponse = options.resolveWithFullResponse === true ? true : false; Loading
test/spec/request-test.js +29 −2 Original line number Diff line number Diff line Loading @@ -110,7 +110,8 @@ describe('Request-Promise', function () { var expectedOptions = { uri: 'http://localhost:1/200', simple: true, resolveWithFullResponse: false resolveWithFullResponse: false, transform: undefined }; rp('http://localhost:1/200') Loading Loading @@ -146,7 +147,8 @@ describe('Request-Promise', function () { var expectedOptions = { uri: 'http://localhost:4000/404', simple: true, resolveWithFullResponse: false resolveWithFullResponse: false, transform: undefined }; rp('http://localhost:4000/404') Loading Loading @@ -373,6 +375,31 @@ describe('Request-Promise', function () { }); it('for HEAD by default', function () { return rp.head('http://localhost:4000/200') .then(function (transformedResponse) { expect(transformedResponse['content-type']).to.eql('text/plain'); }); }); it('but still letting to overwrite the default transform for HEAD', function () { var options = { url: 'http://localhost:4000/200', transform: function () { return 'test'; } }; return rp.head(options) .then(function (transformedResponse) { expect(transformedResponse).to.eql('test'); }); }); }); describe('should cover the HTTP method shortcuts', function () { Loading