post-text.js 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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('post text', function (t) {
  7. var req = http.request({
  8. path: '/echo',
  9. method: 'POST'
  10. }, function (res) {
  11. var buffers = []
  12. res.on('end', function () {
  13. t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match')
  14. t.end()
  15. })
  16. res.on('data', function (data) {
  17. buffers.push(data)
  18. })
  19. })
  20. req.write(reference)
  21. req.end()
  22. })
  23. test('post text with data in end()', function (t) {
  24. var req = http.request({
  25. path: '/echo',
  26. method: 'POST'
  27. }, function (res) {
  28. var buffers = []
  29. res.on('end', function () {
  30. t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match')
  31. t.end()
  32. })
  33. res.on('data', function (data) {
  34. buffers.push(data)
  35. })
  36. })
  37. req.end(reference)
  38. })