a zip code crypto-currency system good for red ONLY

post-binary.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // Binary request bodies don't work in a bunch of browsers
  10. var skipVerification = ((browserName === 'IE' && browserVersion <= 10) ||
  11. (browserName === 'Safari' && browserVersion <= 5) ||
  12. (browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari
  13. (browserName === 'Android Browser' && browserVersion <= 4))
  14. var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png')
  15. test('post binary', function (t) {
  16. var req = http.request({
  17. path: '/echo',
  18. method: 'POST'
  19. }, function (res) {
  20. var buffers = []
  21. res.on('end', function () {
  22. if (skipVerification)
  23. t.skip('binary data not preserved on this browser')
  24. else
  25. t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match')
  26. t.end()
  27. })
  28. res.on('data', function (data) {
  29. buffers.push(data)
  30. })
  31. })
  32. req.write(reference)
  33. req.end()
  34. })