You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

4 years ago
  1. var Buffer = require('buffer').Buffer
  2. var fs = require('fs')
  3. var test = require('tape')
  4. var UAParser = require('ua-parser-js')
  5. var http = require('../..')
  6. var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser()
  7. var browserName = browser.name
  8. var browserVersion = browser.major
  9. // Streaming doesn't work in IE9 or below
  10. var skipStreamingCheck = (browserName === 'IE' && browserVersion <= 9)
  11. var COPIES = 1000
  12. var MIN_PIECES = 5
  13. var referenceOnce = fs.readFileSync(__dirname + '/../server/static/basic.txt')
  14. var reference = new Buffer(referenceOnce.length * COPIES)
  15. for(var i = 0; i < COPIES; i++) {
  16. referenceOnce.copy(reference, referenceOnce.length * i)
  17. }
  18. test('text streaming', function (t) {
  19. http.get({
  20. path: '/basic.txt?copies=' + COPIES,
  21. mode: 'prefer-streaming'
  22. }, function (res) {
  23. var buffers = []
  24. res.on('end', function () {
  25. if (skipStreamingCheck)
  26. t.skip('streaming not available on IE <= 8')
  27. else
  28. t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts')
  29. t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
  30. t.end()
  31. })
  32. res.on('data', function (data) {
  33. buffers.push(data)
  34. })
  35. })
  36. })