Sha256: 2303cb78d243ba0ed4dfce7bf73eec5b3d1ba9454d0b7ff6fcbcc656b4eb2080

Contents?: true

Size: 1.98 KB

Versions: 35

Compression:

Stored size: 1.98 KB

Contents

var Buffer = require('buffer').Buffer
var fs = require('fs')
var test = require('tape')
var UAParser = require('ua-parser-js')

var http = require('../..')

var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser()
var browserName = browser.name
var browserVersion = browser.major
// Binary streaming doesn't work in IE10 or below
var skipStreamingCheck = (browserName === 'IE' && browserVersion <= 10)

// Binary data gets corrupted in IE8 or below
var skipVerification = (browserName === 'IE' && browserVersion <= 8)

// IE8 tends to throw up modal dialogs complaining about scripts running too long
// Since streaming doesn't actually work there anyway, just use one copy
var COPIES = skipVerification ? 1 : 20
var MIN_PIECES = 2

var referenceOnce = fs.readFileSync(__dirname + '/../server/static/browserify.png')
var reference = new Buffer(referenceOnce.length * COPIES)
for(var i = 0; i < COPIES; i++) {
	referenceOnce.copy(reference, referenceOnce.length * i)
}

test('binary streaming', function (t) {
	http.get({
		path: '/browserify.png?copies=' + COPIES,
		mode: 'allow-wrong-content-type'
	}, function (res) {
		var buffers = []
		res.on('end', function () {
			if (skipVerification)
				t.skip('binary data not preserved on IE <= 8')
			else
				t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')

			if (skipStreamingCheck)
				t.skip('streaming not available on IE <= 8')
			else
				t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts')
			t.end()
		})

		res.on('data', function (data) {
			buffers.push(data)
		})
	})
})

test('large binary request without streaming', function (t) {
	http.get({
		path: '/browserify.png?copies=' + COPIES,
		mode: 'default',
	}, function (res) {
		var buffers = []
		res.on('end', function () {
			if (skipVerification)
				t.skip('binary data not preserved on IE <= 8')
			else
				t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
			t.end()
		})

		res.on('data', function (data) {
			buffers.push(data)
		})
	})
})

Version data entries

35 entries across 34 versions & 12 rubygems

Version Path
ilog-0.4.0 node_modules/stream-http/test/browser/binary-streaming.js
ilog-0.3.3 node_modules/stream-http/test/browser/binary-streaming.js
jester-data-8.0.0 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-5.2.1 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-2.0.1 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-1.1.0 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-1.0.0 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-0.0.0.1.0 node_modules/stream-http/test/browser/binary-streaming.js
ezii-os-0.0.0.0.1 node_modules/stream-http/test/browser/binary-streaming.js
optimacms-0.4.3 spec/dummy/node_modules/stream-http/test/browser/binary-streaming.js
optimacms-0.4.2 spec/dummy/node_modules/stream-http/test/browser/binary-streaming.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/stream-http/test/browser/binary-streaming.js
locomotivecms-3.4.0 app/javascript/node_modules/stream-http/test/browser/binary-streaming.js
cortex-0.1.3 spec/dummy/node_modules/stream-http/test/browser/binary-streaming.js
dragonfly_puppeteer-0.1.0 node_modules/stream-http/test/browser/binary-streaming.js