body-empty.js 656 B

1234567891011121314151617181920212223242526272829
  1. var Buffer = require('buffer').Buffer
  2. var fs = require('fs')
  3. var test = require('tape')
  4. var http = require('../..')
  5. var reference = fs.readFileSync(__dirname + '/../server/static/basic.txt')
  6. test('get body empty', function (t) {
  7. var req = http.request({
  8. path: '/verifyEmpty',
  9. method: 'GET'
  10. }, function (res) {
  11. var buffers = []
  12. res.on('end', function () {
  13. console.log(Buffer.concat(buffers).toString('utf8'))
  14. t.ok(Buffer.from('empty').equals(Buffer.concat(buffers)), 'response body indicates request body was empty')
  15. t.end()
  16. })
  17. res.on('data', function (data) {
  18. buffers.push(data)
  19. })
  20. })
  21. req.write(reference)
  22. req.end()
  23. })