diff --git a/lib/transports/http.js b/lib/transports/http.js index 6ded863b..df209300 100644 --- a/lib/transports/http.js +++ b/lib/transports/http.js @@ -3,7 +3,7 @@ /** * The Http transport backend * @module skyring/lib/transports/http - * @author Eric Satterwhite + * @author Eric Satterwhite * @since 1.0.0 * @requires http * @requires request @@ -12,6 +12,7 @@ */ const STATUS_CODES = require('http').STATUS_CODES + , method_exp = /^(post|put|patch|delete|get|options|head)$/i , request = require('request') , debug = require('debug')('skyring:transport:http') ; @@ -27,12 +28,23 @@ const STATUS_CODES = require('http').STATUS_CODES **/ module.exports = function makeRequest( method, url, payload, id, cache) { const isJSON = typeof payload === 'object' - const options = { - body: payload || "" - , json: isJSON - }; + , _method = method.toLowerCase() + , options = { + body: payload || "" + , json: isJSON + }; + + + if( method_exp.test(method) && typeof request[_method] !== 'function' ) { + const t = cache.get(id) + t && clearTimeout(t.timer) + cache.delete(id) + debug('unable to execute http transport', method, id) + return + } + debug('executing http transport %s', id, method); - request[method.toLowerCase()](url, options, (err, res, body) => { + request[_method](url, options, (err, res, body) => { if(err){ debug('timer fail'); return cache.remove(id);