@@ -688,14 +688,18 @@ Manager.prototype.generateId = function () {
688
688
*/
689
689
690
690
Manager . prototype . handleHandshake = function ( data , req , res ) {
691
- var self = this ;
691
+ var self = this
692
+ , origin = req . headers . origin
693
+ , headers = {
694
+ 'Content-Type' : 'text/plain'
695
+ } ;
692
696
693
697
function writeErr ( status , message ) {
694
698
if ( data . query . jsonp ) {
695
699
res . writeHead ( 200 , { 'Content-Type' : 'application/javascript' } ) ;
696
700
res . end ( 'io.j[' + data . query . jsonp + '](new Error("' + message + '"));' ) ;
697
701
} else {
698
- res . writeHead ( status , { 'Content-Type' : 'text/plain' } ) ;
702
+ res . writeHead ( status , headers ) ;
699
703
res . end ( message ) ;
700
704
}
701
705
} ;
@@ -712,6 +716,15 @@ Manager.prototype.handleHandshake = function (data, req, res) {
712
716
713
717
var handshakeData = this . handshakeData ( data ) ;
714
718
719
+ if ( origin ) {
720
+ // https://developer.mozilla.org/En/HTTP_Access_Control
721
+ headers [ 'Access-Control-Allow-Origin' ] = '*' ;
722
+
723
+ if ( req . headers . cookie ) {
724
+ headers [ 'Access-Control-Allow-Credentials' ] = 'true' ;
725
+ }
726
+ }
727
+
715
728
this . authorize ( handshakeData , function ( err , authorized , newData ) {
716
729
if ( err ) return error ( err ) ;
717
730
@@ -728,7 +741,7 @@ Manager.prototype.handleHandshake = function (data, req, res) {
728
741
hs = 'io.j[' + data . query . jsonp + '](' + JSON . stringify ( hs ) + ');' ;
729
742
res . writeHead ( 200 , { 'Content-Type' : 'application/javascript' } ) ;
730
743
} else {
731
- res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
744
+ res . writeHead ( 200 , headers ) ;
732
745
}
733
746
734
747
res . end ( hs ) ;
0 commit comments