Skip to content

Commit

Permalink
check http method before executing
Browse files Browse the repository at this point in the history
validate the http method on the callback payload before
trying to execute the time.

clear and delete if it doesn't pass
  • Loading branch information
esatterwhite committed Jan 14, 2017
1 parent c0c2f19 commit cfd2456
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/transports/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
;
Expand All @@ -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);
Expand Down

0 comments on commit cfd2456

Please sign in to comment.