mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Fixed multipart streaming so that it works properly again (especially for cross-domain requests). Tested on Firefox 3.6.4.
This commit is contained in:
committed by
Visnu Pitiyanuvath
parent
0e483a05a5
commit
71d80181fa
@@ -11,17 +11,26 @@ this['xhr-multipart'] = Client.extend({
|
||||
|
||||
_onConnect: function(req, res){
|
||||
var self = this, body = '';
|
||||
var headers = {};
|
||||
// For newer browsers that support CORS (cross-domain XHR) -- see: https://developer.mozilla.org/En/HTTP_Access_Control
|
||||
if (req.headers['origin'] && this._verifyOrigin(req.headers['origin'])) {
|
||||
headers['Access-Control-Allow-Origin'] = req.headers['origin'];
|
||||
headers['Access-Control-Allow-Credentials'] = 'true';
|
||||
}
|
||||
if (typeof req.headers['access-control-request-method'] != 'undefined') {
|
||||
// CORS preflight message
|
||||
headers['Access-Control-Allow-Methods'] = req.headers['access-control-request-method'];
|
||||
res.writeHead(200, headers);
|
||||
res.write('ok');
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
switch (req.method){
|
||||
case 'GET':
|
||||
var self = this;
|
||||
this.__super__(req, res);
|
||||
var headers = {'Content-Type': 'multipart/x-mixed-replace;boundary="socketio"', 'Connection': 'keep-alive'};
|
||||
// For newer browsers that support CORS (cross-domain XHR) -- see: https://developer.mozilla.org/En/HTTP_Access_Control
|
||||
if (this.request.headers['origin'] && this._verifyOrigin(this.request.headers['origin'])) {
|
||||
headers['Access-Control-Allow-Origin'] = this.request.headers['origin'];
|
||||
if (this.request.headers['cookie'])
|
||||
headers['Access-Control-Allow-Credentials'] = 'true';
|
||||
}
|
||||
headers['Content-Type'] = 'multipart/x-mixed-replace;boundary="socketio"';
|
||||
headers['Connection'] = 'keep-alive';
|
||||
this.request.connection.addListener('end', function(){ self._onClose(); });
|
||||
this.response.useChunkedEncodingByDefault = false;
|
||||
this.response.shouldKeepAlive = true;
|
||||
@@ -39,16 +48,17 @@ this['xhr-multipart'] = Client.extend({
|
||||
|
||||
case 'POST':
|
||||
req.addListener('data', function(message){
|
||||
body += message;
|
||||
body += message.toString();
|
||||
});
|
||||
req.addListener('end', function(){
|
||||
try {
|
||||
var msg = qs.parse(body);
|
||||
self._onMessage(msg.data);
|
||||
} catch(e){}
|
||||
res.writeHead(200);
|
||||
} catch(e){}
|
||||
res.writeHead(200, headers);
|
||||
res.write('ok');
|
||||
res.end();
|
||||
body = '';
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user