[Pkg-javascript-commits] [node-stream-http] 17/208: Support binary requests in IE9

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:23 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 8985094a2b98c99c050aa8f2966340a2b68f5beb
Author: John Hiesey <john at hiesey.com>
Date:   Thu Jul 2 20:00:16 2015 -0700

    Support binary requests in IE9
---
 .zuul.yml            |  2 +-
 lib/capability.js    |  1 +
 lib/request.js       |  4 +++-
 lib/response.js      | 16 ++++++++++++++--
 package.json         |  1 +
 test/tests/binary.js | 11 ++++++++++-
 6 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/.zuul.yml b/.zuul.yml
index 83f99f0..7a146a7 100644
--- a/.zuul.yml
+++ b/.zuul.yml
@@ -11,7 +11,7 @@ browsers:
   - name: opera
     version: 11..latest
   - name: iphone
-    version: 4.3..latest
+    version: 5.0..latest
   - name: android
     version: 4.0..latest
 server: ./test/server/index.js
diff --git a/lib/capability.js b/lib/capability.js
index f76a397..09d8890 100644
--- a/lib/capability.js
+++ b/lib/capability.js
@@ -20,5 +20,6 @@ exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
 exports.msstream = haveSlice && checkTypeSupport('ms-stream')
 exports.mozchunkedarraybuffer = haveArrayBuffer && checkTypeSupport('moz-chunked-arraybuffer')
 exports.overrideMimeType = util.isFunction(xhr.overrideMimeType)
+exports.vbArray = util.isFunction(window.VBArray)
 
 xhr = null // Help gc
diff --git a/lib/request.js b/lib/request.js
index fcdac1c..9124cbf 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -29,6 +29,8 @@ function decideMode (preferBinary) {
 		return 'ms-stream'
 	} else if (capability.arraybuffer && preferBinary) {
 		return 'arraybuffer'
+	} else if (capability.vbArray && preferBinary) {
+		return 'text:vbarray'
 	} else {
 		return 'text'
 	}
@@ -133,7 +135,7 @@ ClientRequest.prototype._onFinish = function () {
 
 		// Can't set responseType on really old browsers
 		if ('responseType' in xhr)
-			xhr.responseType = self._mode
+			xhr.responseType = self._mode.split(':')[0]
 
 		if ('withCredentials' in xhr)
 			xhr.withCredentials = !!opts.credentials
diff --git a/lib/response.js b/lib/response.js
index 9c07e24..0e81cfc 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -88,9 +88,21 @@ IncomingMessage.prototype._onXHRReadyStateChange = function () {
 
 	var xhr = self._xhr
 
-	var response
+	var response = null
 	switch (self._mode) {
-		case 'text': // slice
+		case 'text:vbarray': // For IE9
+			if (xhr.readyState !== rStates.DONE)
+				break
+			try {
+				// This fails in IE8
+				response = new window.VBArray(xhr.responseBody).toArray()
+			} catch (e) {}
+			if (response !== null) {
+				self.push(new Buffer(response))
+				break
+			}
+			// Falls through in IE8	
+		case 'text':
 			response = xhr.responseText
 			if (response.length > self._pos) {
 				var newData = response.substr(self._pos)
diff --git a/package.json b/package.json
index 7a78326..fafadb4 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
     "brfs": "^1.4.0",
     "express": "^4.13.0",
     "tape": "^4.0.0",
+    "ua-parser-js": "^0.7.7",
     "zuul": "^3.1.0"
   }
 }
diff --git a/test/tests/binary.js b/test/tests/binary.js
index 4e595a1..cceced3 100644
--- a/test/tests/binary.js
+++ b/test/tests/binary.js
@@ -1,6 +1,11 @@
 var Buffer = require('buffer').Buffer
 var fs = require('fs');
 var test = require('tape')
+var UAParser = require('ua-parser-js')
+
+var browserType = (new UAParser()).setUA(navigator.userAgent).getBrowser()
+// Binary data gets corrupted in IE8 or below
+var skipVerification = (browserType.name === 'IE' && browserType.major <= 8)
 
 var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png');
 
@@ -11,7 +16,11 @@ test('binary download', function (t) {
 		var buffers = []
 
 		res.on('end', function () {
-			t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
+			if (skipVerification) {
+				t.skip('binary data not preserved on IE <= 8')
+			} else {
+				t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
+			}
 			t.end()
 		})
 

-- 
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