/*jshint laxcomma: true, smarttabs: true, node:true, esnext:true*/
'use strict';
/**
 * The Http transport backend
 * @module skyring/lib/transports/http
 * @author Eric Satterwhite 
 * @since 1.0.0
 * @requires http
 * @requires request
 * @requires debug
 * @requires skyring/lib/timer
 */

const STATUS_CODES = require('http').STATUS_CODES
    , request = require('request')
    , debug   = require('debug')('skyring:transport:http')
    ;

/**
 * Dispatches an http request
 * @function
 * @alias module:skyring/lib/transports/http
 * @param {String} method The http method to use when dispatching the request
 * @param {String} url the url to target when dispatching
 * @param {String} payload The data payload to include in the request
 * @param {String} id The id of the timer being executed
 **/
module.exports = function makeRequest( method, url, payload, id, cache) {
  const isJSON = typeof payload === 'object'
  const options = {
    body: payload || ""
  , json: isJSON
  };
  debug('executing http transport %s', id);
  request[method](url, options, (err, res, body) => {
    if(err){
      debug('timer fail');
      return cache.remove(id);
    }
    if(res.statusCode > 299 ){
      debug('timer fail');
      const err = new Error(STATUS_CODES[res.statusCode])
      err.code = res.statusCode = res.statusCode;
      console.error(err, body)
      return cache.remove(id);
    }

    debug('timer sucess');
    return cache.remove(id);
  });
};

@@ -1023,16 +1023,24 @@
  %25s', id
+, method
 );%0A  req
@@ -1050,16 +1050,30 @@
 t%5Bmethod
+.toLowerCase()
 %5D(url, o

lower case the http method