
var https = require('https')

module.exports = function(state, action, callback) {
  var url = action.input['URL']
  var method = action.input.Method
  var headers = action.input.Headers
  var body = action.input.Body
  var query = action.input.Query

  headers['Content-length'] = body.length

  var options = {
    url: url,
    method: method,
    headers: headers
  }

  var req = https.request(options, function(res){
    var body = ''
    res.setEncoding('utf8')
    res.on('data', function(data){
      body += data;
    });
    res.on('end', function(){
      callback(null, body)
    })
  })

  if (body) {
    req.write(body)
  }

  req.end()
}
