File tree 4 files changed +33
-10
lines changed
4 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -220,10 +220,6 @@ Request.prototype.create = function () {
220
220
xhr . setRequestHeader ( 'Accept' , '*/*' ) ;
221
221
} catch ( e ) { }
222
222
223
- if ( this . supportsBinary ) {
224
- xhr . responseType = 'arraybuffer' ;
225
- }
226
-
227
223
// ie6 check
228
224
if ( 'withCredentials' in xhr ) {
229
225
xhr . withCredentials = true ;
@@ -245,8 +241,8 @@ Request.prototype.create = function () {
245
241
if ( xhr . readyState === 2 ) {
246
242
try {
247
243
var contentType = xhr . getResponseHeader ( 'Content-Type' ) ;
248
- if ( contentType ! == 'application/octet-stream' ) {
249
- xhr . responseType = 'text ' ;
244
+ if ( self . supportsBinary && contentType = == 'application/octet-stream' ) {
245
+ xhr . responseType = 'arraybuffer ' ;
250
246
}
251
247
} catch ( e ) { }
252
248
}
@@ -359,8 +355,6 @@ Request.prototype.onLoad = function () {
359
355
} catch ( e ) { }
360
356
if ( contentType === 'application/octet-stream' ) {
361
357
data = this . xhr . response || this . xhr . responseText ;
362
- } else if ( this . xhr . responseType === 'arraybuffer' ) {
363
- data = String . fromCharCode . apply ( null , new Uint8Array ( this . xhr . response ) ) ;
364
358
} else {
365
359
data = this . xhr . responseText ;
366
360
}
Original file line number Diff line number Diff line change @@ -62,10 +62,28 @@ describe('connection', function () {
62
62
if ( global . Worker ) {
63
63
it ( 'should work in a worker' , function ( done ) {
64
64
var worker = new Worker ( '/test/support/worker.js' ) ;
65
+ var msg = 0 ;
66
+ var utf8yay = 'пойду сать всем мпокойной ночи' ;
65
67
worker . onmessage = function ( e ) {
66
- expect ( e . data ) ;
67
- done ( ) ;
68
+ msg ++ ;
69
+ if ( msg === 1 ) {
70
+ expect ( e . data ) . to . be ( 'hi' ) ;
71
+ } else if ( msg < 11 ) {
72
+ expect ( e . data ) . to . be ( utf8yay ) ;
73
+ } else if ( msg < 20 ) {
74
+ testBinary ( e . data ) ;
75
+ } else {
76
+ testBinary ( e . data ) ;
77
+ done ( ) ;
78
+ }
68
79
} ;
80
+
81
+ function testBinary ( data ) {
82
+ var byteArray = new Uint8Array ( data ) ;
83
+ for ( var i = 0 ; i < byteArray . byteLength ; i ++ ) {
84
+ expect ( byteArray [ i ] ) . to . be ( i ) ;
85
+ }
86
+ }
69
87
} ) ;
70
88
}
71
89
Original file line number Diff line number Diff line change 3
3
importScripts ( '/test/support/engine.io.js' ) ;
4
4
5
5
var socket = new eio . Socket ( ) ;
6
+
7
+ var count = 0 ;
6
8
socket . on ( 'message' , function ( msg ) {
9
+ count ++ ;
10
+ if ( count < 10 ) {
11
+ socket . send ( 'give utf8' ) ;
12
+ } else if ( count < 20 ) {
13
+ socket . send ( 'give binary' ) ;
14
+ }
7
15
postMessage ( msg ) ;
8
16
} ) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ server.on('connection', function (socket) {
32
32
}
33
33
socket . send ( abv ) ;
34
34
return ;
35
+ } else if ( data === 'give utf8' ) {
36
+ socket . send ( 'пойду сать всем мпокойной ночи' ) ;
37
+ return ;
35
38
}
36
39
37
40
socket . send ( data ) ;
You can’t perform that action at this time.
0 commit comments