File tree Expand file tree Collapse file tree 4 files changed +34
-13
lines changed Expand file tree Collapse file tree 4 files changed +34
-13
lines changed Original file line number Diff line number Diff line change @@ -220,10 +220,6 @@ Request.prototype.create = function () {
220220 xhr . setRequestHeader ( 'Accept' , '*/*' ) ;
221221 } catch ( e ) { }
222222
223- if ( this . supportsBinary ) {
224- xhr . responseType = 'arraybuffer' ;
225- }
226-
227223 // ie6 check
228224 if ( 'withCredentials' in xhr ) {
229225 xhr . withCredentials = true ;
@@ -245,8 +241,8 @@ Request.prototype.create = function () {
245241 if ( xhr . readyState === 2 ) {
246242 try {
247243 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 ' ;
250246 }
251247 } catch ( e ) { }
252248 }
@@ -358,11 +354,7 @@ Request.prototype.onLoad = function () {
358354 contentType = this . xhr . getResponseHeader ( 'Content-Type' ) ;
359355 } catch ( e ) { }
360356 if ( contentType === 'application/octet-stream' ) {
361- if ( this . xhr . responseType === 'arraybuffer' ) {
362- data = this . xhr . response || this . xhr . responseText ;
363- } else {
364- data = String . fromCharCode . apply ( null , new Uint8Array ( this . xhr . response ) ) ;
365- }
357+ data = this . xhr . response || this . xhr . responseText ;
366358 } else {
367359 data = this . xhr . responseText ;
368360 }
Original file line number Diff line number Diff line change @@ -62,10 +62,28 @@ describe('connection', function () {
6262 if ( global . Worker ) {
6363 it ( 'should work in a worker' , function ( done ) {
6464 var worker = new Worker ( '/test/support/worker.js' ) ;
65+ var msg = 0 ;
66+ var utf8yay = 'пойду сать всем мпокойной ночи' ;
6567 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+ }
6879 } ;
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+ }
6987 } ) ;
7088 }
7189
Original file line number Diff line number Diff line change 33importScripts ( '/test/support/engine.io.js' ) ;
44
55var socket = new eio . Socket ( ) ;
6+
7+ var count = 0 ;
68socket . 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+ }
715 postMessage ( msg ) ;
816} ) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ server.on('connection', function (socket) {
3232 }
3333 socket . send ( abv ) ;
3434 return ;
35+ } else if ( data === 'give utf8' ) {
36+ socket . send ( 'пойду сать всем мпокойной ночи' ) ;
37+ return ;
3538 }
3639
3740 socket . send ( data ) ;
You can’t perform that action at this time.
0 commit comments