stream-http
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -20,8 +20,13 @@ exports.fetch = isFunction(window.fetch) && isFunction(window.ReadableByteStream) | ||
var haveArrayBuffer = isFunction(window.ArrayBuffer) | ||
// For some strange reason, Safari 7.0 reports typeof window.ArrayBuffer === 'object'. | ||
// Safari 7.1 appears to have fixed this bug. | ||
var haveArrayBuffer = typeof window.ArrayBuffer !== 'undefined' | ||
var haveSlice = haveArrayBuffer && isFunction(window.ArrayBuffer.prototype.slice) | ||
exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer') | ||
exports.msstream = haveSlice && checkTypeSupport('ms-stream') | ||
exports.mozchunkedarraybuffer = haveArrayBuffer && checkTypeSupport('moz-chunked-arraybuffer') | ||
// These next two tests unavoidably show warnings in Chrome. Since fetch will always | ||
// be used if it's available, just return false for these to avoid the warnings. | ||
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream') | ||
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer && | ||
checkTypeSupport('moz-chunked-arraybuffer') | ||
exports.overrideMimeType = isFunction(xhr.overrideMimeType) | ||
@@ -28,0 +33,0 @@ exports.vbArray = isFunction(window.VBArray) |
@@ -45,10 +45,11 @@ // var Base64 = require('Base64') | ||
if (opts.mode === 'prefer-streaming') { | ||
// If streaming is a high priority but binary compatibility isn't | ||
// If streaming is a high priority but binary compatibility and | ||
// the accuracy of the 'content-type' header aren't | ||
preferBinary = false | ||
} else if (opts.mode === 'prefer-fast') { | ||
// If binary is preferred for speed | ||
} else if (opts.mode === 'allow-wrong-content-type') { | ||
// If streaming is more important than preserving the 'content-type' header | ||
preferBinary = !capability.overrideMimeType | ||
} else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') { | ||
// Use binary if text streaming may corrupt data or the content-type header, or for speed | ||
preferBinary = true | ||
} else if (!opts.mode || opts.mode === 'default') { | ||
// By default, use binary if text streaming may corrupt data | ||
preferBinary = !capability.overrideMimeType | ||
} else { | ||
@@ -55,0 +56,0 @@ throw new Error('Invalid value for opts.mode') |
{ | ||
"name": "stream-http", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Streaming http in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,10 +54,17 @@ # stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](https://travis-ci.org/jhiesey/stream-http) | ||
* 'default' (or any falsy value, including undefined): Try to provide partial data before | ||
the equest completes, but not at the cost of correctness for binary data. In some cases | ||
the implementation may be a bit slow. | ||
the request completes, but not at the cost of correctness for binary data or correctness of | ||
the 'content-type' response header. This mode will also avoid slower code paths whenever | ||
possible, which is particularly useful when making large requests in a browser like Safari | ||
that has a weaker javascript engine. | ||
* 'allow-wrong-content-type': Provides partial data in more cases than 'default', but | ||
at the expense of causing the 'content-type' response header to be incorrectly reported | ||
(as 'text/plain; charset=x-user-defined') in some browsers, notably Safari and Chrome 42 | ||
and older. Preserves binary data whenever possible. In some cases the implementation may | ||
also be a bit slow. This was the default in versions of this module before 1.5. | ||
* 'prefer-stream': Provide data before the request completes even if binary data (anything | ||
that isn't a single-byte ASCII or utf8 character) will be corrupted. Of course, this option | ||
is only safe for text data. | ||
* 'prefer-fast': Use an implementation that does less processing even if it means that | ||
partial data isn't available. This is particularly useful when making large requests in | ||
a browser like Safari that has a weaker javascript engine. | ||
is only safe for text data. May also cause the 'content-type' response header to be | ||
incorrectly reported (as 'text/plain; charset=x-user-defined'). | ||
* 'prefer-fast': Deprecated; now a synonym for 'default', which has the same performance | ||
characteristics as this mode did in versions before 1.5. | ||
@@ -64,0 +71,0 @@ ### Features missing compared to node |
@@ -29,3 +29,6 @@ var Buffer = require('buffer').Buffer | ||
test('binary streaming', function (t) { | ||
http.get('/browserify.png?copies=' + COPIES, function (res) { | ||
http.get({ | ||
path: '/browserify.png?copies=' + COPIES, | ||
mode: 'allow-wrong-content-type' | ||
}, function (res) { | ||
var buffers = [] | ||
@@ -54,3 +57,3 @@ res.on('end', function () { | ||
path: '/browserify.png?copies=' + COPIES, | ||
mode: 'prefer-fast', | ||
mode: 'default', | ||
}, function (res) { | ||
@@ -57,0 +60,0 @@ var buffers = [] |
@@ -5,2 +5,3 @@ var Buffer = require('buffer').Buffer | ||
var test = require('tape') | ||
var UAParser = require('ua-parser-js') | ||
@@ -57,2 +58,30 @@ var http = require('../..') | ||
}) | ||
}) | ||
test('content-type response header', function (t) { | ||
http.get('/testHeaders', function (res) { | ||
t.equal(res.headers['content-type'], 'application/json', 'content-type preserved') | ||
t.end() | ||
}) | ||
}) | ||
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() | ||
var browserName = browser.name | ||
var browserVersion = browser.major | ||
// The content-type header is broken when 'prefer-streaming' or 'allow-wrong-content-type' | ||
// is passed in browsers that rely on xhr.overrideMimeType(), namely older chrome and newer safari | ||
var wrongMimeType = ((browserName === 'Chrome' && browserVersion <= 42) || | ||
((browserName === 'Safari' || browserName === 'Mobile Safari') && browserVersion >= 6)) | ||
test('content-type response header with forced streaming', function (t) { | ||
http.get({ | ||
path: '/testHeaders', | ||
mode: 'prefer-streaming' | ||
}, function (res) { | ||
if (wrongMimeType) | ||
t.equal(res.headers['content-type'], 'text/plain; charset=x-user-defined', 'content-type overridden') | ||
else | ||
t.equal(res.headers['content-type'], 'application/json', 'content-type preserved') | ||
t.end() | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71079
1027
103