[Pkg-javascript-commits] [node-stream-http] 05/208: Fix IE

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-http.

commit c5127e4f1b489d6dbe20cde67f5bba40cf20b02d
Author: John Hiesey <john at hiesey.com>
Date:   Wed Jul 1 19:53:08 2015 -0700

    Fix IE
---
 capability.js | 48 +++++++++++++++++++++++++++++++++---------------
 request.js    | 29 ++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/capability.js b/capability.js
index 951cb22..2dc7c6b 100644
--- a/capability.js
+++ b/capability.js
@@ -2,9 +2,7 @@ var util = require('util')
 
 exports.fetch = util.isFunction(window.fetch)
 
-function checkTypeSupport (type) {
-	var xhr = new window.XMLHttpRequest()
-	xhr.open('GET', '/')
+function checkTypeSupport (xhr, type) {
 	try {
 		xhr.responseType = type
 		return xhr.responseType === type
@@ -12,18 +10,38 @@ function checkTypeSupport (type) {
 	return false
 }
 
+var xhr = new window.XMLHttpRequest()
+xhr.open('GET', '/')
+
 exports.arraybuffer = checkTypeSupport('arraybuffer')
-exports.msstream = checkTypeSupport('ms-stream')
+exports.msstream = checkTypeSupport('ms-stream') && util.isFunction(ArrayBuffer.prototype.slice)
 exports.mozchunkedarraybuffer = checkTypeSupport('moz-chunked-arraybuffer')
+exports.overrideMimeType = util.isFunction(xhr.overrideMimeType)
 
-if (exports.fetch) {
-	exports.mode = 'fetch'
-} else if (exports.mozchunkedarraybuffer) {
-	exports.mode = 'moz-chunked-arraybuffer'
-} else if (exports.msstream) {
-	exports.mode = 'ms-stream'
-// } else if (exports.arraybuffer) {
-// 	exports.mode = 'arraybuffer'
-} else {
-	exports.mode = 'text'
-}
+xhr = null // Help gc
+
+// exports.getMode = function (preferBinary) {
+// 	if (exports.fetch) {
+// 		exports.mode = 'fetch'
+// 	} else if (exports.mozchunkedarraybuffer) {
+// 		exports.mode = 'moz-chunked-arraybuffer'
+// 	} else if (exports.msstream) {
+// 		exports.mode = 'ms-stream'
+// 	} else if (exports.arraybuffer && preferBinary) {
+// 		exports.mode = 'arraybuffer'
+// 	} else {
+// 		exports.mode = 'text'
+// 	}
+// }
+
+/*
+// correctness: might need binary
+// speed: might want binary
+
+// normally, stream if correctness not affected. If force stream, . If force, ignore correctness
+
+// force stream 			Use text
+// prefer stream 			Use text if overridemimetype is available
+// force binary (speedy)	Use binary
+
+*/
\ No newline at end of file
diff --git a/request.js b/request.js
index f769d4e..0b776a9 100644
--- a/request.js
+++ b/request.js
@@ -18,6 +18,20 @@ var rStates = response.readyStates
 // 	return to
 // }
 
+function decideMode (preferBinary) {
+	if (capability.fetch) {
+		return 'fetch'
+	} else if (capability.mozchunkedarraybuffer) {
+		return 'moz-chunked-arraybuffer'
+	} else if (capability.msstream) {
+		return 'ms-stream'
+	} else if (capability.arraybuffer && preferBinary) {
+		return 'arraybuffer'
+	} else {
+		return 'text'
+	}
+}
+
 var ClientRequest = module.exports = function (opts) {
 	var self = this
 	stream.Writable.call(self)
@@ -29,7 +43,20 @@ var ClientRequest = module.exports = function (opts) {
 		self.setHeader(name, opts.headers[name])
 	})
 
-	self._mode = capability.mode
+	var preferBinary
+	if (opts.mode === 'prefer-stream') {
+		// If streaming is a high priority but binary compatibility isn't
+		preferBinary = false
+	} else if (opts.mode === 'prefer-binary') {
+		// If binary compatibility is the highest priority
+		preferBinary = true
+	} else if (!opts.mode || opts.mode === 'default') {
+		// By default, use binary if text streaming may corrupt data
+		preferBinary = !capability.overrideMimeType
+	} else {
+		throw new Error('Invalid value for opts.mode')
+	}
+	self._mode = decideMode(preferBinary)
 
 	self.on('finish', self._onFinish.bind(self))
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-http.git



More information about the Pkg-javascript-commits mailing list