@@ -205,11 +205,6 @@ Request.prototype.create = function () {
205
205
}
206
206
}
207
207
} catch ( e ) { }
208
- if ( this . supportsBinary ) {
209
- // This has to be done after open because Firefox is stupid
210
- // http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension
211
- xhr . responseType = 'arraybuffer' ;
212
- }
213
208
214
209
if ( 'POST' === this . method ) {
215
210
try {
@@ -243,6 +238,15 @@ Request.prototype.create = function () {
243
238
} ;
244
239
} else {
245
240
xhr . onreadystatechange = function ( ) {
241
+ if ( xhr . readyState === 2 ) {
242
+ var contentType ;
243
+ try {
244
+ contentType = xhr . getResponseHeader ( 'Content-Type' ) ;
245
+ } catch ( e ) { }
246
+ if ( contentType === 'application/octet-stream' ) {
247
+ xhr . responseType = 'arraybuffer' ;
248
+ }
249
+ }
246
250
if ( 4 !== xhr . readyState ) return ;
247
251
if ( 200 === xhr . status || 1223 === xhr . status ) {
248
252
self . onLoad ( ) ;
@@ -348,26 +352,12 @@ Request.prototype.onLoad = function () {
348
352
try {
349
353
var contentType ;
350
354
try {
351
- contentType = this . xhr . getResponseHeader ( 'Content-Type' ) . split ( ';' ) [ 0 ] ;
355
+ contentType = this . xhr . getResponseHeader ( 'Content-Type' ) ;
352
356
} catch ( e ) { }
353
357
if ( contentType === 'application/octet-stream' ) {
354
358
data = this . xhr . response || this . xhr . responseText ;
355
359
} else {
356
- if ( ! this . supportsBinary ) {
357
- data = this . xhr . responseText ;
358
- } else {
359
- try {
360
- data = String . fromCharCode . apply ( null , new Uint8Array ( this . xhr . response ) ) ;
361
- } catch ( e ) {
362
- var ui8Arr = new Uint8Array ( this . xhr . response ) ;
363
- var dataArray = [ ] ;
364
- for ( var idx = 0 , length = ui8Arr . length ; idx < length ; idx ++ ) {
365
- dataArray . push ( ui8Arr [ idx ] ) ;
366
- }
367
-
368
- data = String . fromCharCode . apply ( null , dataArray ) ;
369
- }
370
- }
360
+ data = this . xhr . responseText ;
371
361
}
372
362
} catch ( e ) {
373
363
this . onError ( e ) ;
0 commit comments