'use strict'

const DELAY = parseInt(process.env.DELAY, 10) || 2000

const bigBuff = Buffer.alloc(2 * 1024 * 1024, 'HellWorld ')

exports.handleBodyRequest = (conn) => {
  conn.end(bigBuff)
}

exports.handleDelayRequest = (conn) => {
  conn.write('Delay start')
  setTimeout(() => {
    conn.end(`Waited for ${DELAY}ms`)
  }, DELAY)

  conn.on('error', console.warn)
}

exports.handleImmediateResponse = (conn) => {
  conn.end(`Immediate tcp response`)
}

'use strict'

const DELAY = parseInt(process.env.DELAY, 10) || 2000

const bigBuff = Buffer.alloc(2 * 1024 * 1024, 'HellWorld ')

function sendHttpHeaders (conn) {
  conn.write('HTTP/1.1 200 OK\n')
  conn.write('Content-Type: text/plain\n')
  conn.write('\n')
}

exports.handleBodyRequest = (conn) => {
  sendHttpHeaders(conn)
  conn.end(bigBuff)
}

exports.handleDelayRequest = (conn) => {
  sendHttpHeaders(conn)
  conn.write('Delay start')
  setTimeout(() => {
    conn.end(`Waited for ${DELAY}ms`)
  }, DELAY)

  conn.on('error', console.warn)
}

exports.handleImmediateResponse = (conn) => {
  sendHttpHeaders(conn)
  conn.end(`Immediate tcp response`)
}

Send HTTP response on TCP channels
Send HTTP response on TCP channels

The load testing tools don't support plain TCP.

OHM-556
