       }
     }
     req = http.request(opts, (response) ->
+      hasEnded = false
       # response.statusCode
       # response.headers
       # response.statusCode

        socket.on 'timeout', -> req.abort()

    req.on 'error', (e) ->
      return if callbacked
      callback(e)
      callbacked = true
      return

    req.write(queryBuffer.toString('utf-8'))

        return

      response.on 'close', (err) ->
        return if hasEnded
        callback({
          error: 'close'
          message: err
        })
        return

      response.on 'end', ->
        hasEnded = true
        chunks = chunks.join('')
        if response.statusCode isnt 200
          callback({
            error: 'bad status code'
            detail: response.statusCode
            message: chunks
          })
          return

        try
          chunks = JSON.parse(chunks)
        catch e
          callback({
            error: 'json parse'
            message: e.message
          })
          return

        callback(null, chunks)
        return
      return
    )
