Simplified XHR#doWrite

This commit is contained in:
Guillermo Rauch
2012-01-03 12:59:40 -08:00
parent 3aa755e9f9
commit 1273fc4f10

View File

@@ -34,18 +34,14 @@ XHR.prototype.__proto__ = Polling.prototype;
* @api private
*/
XHRPolling.prototype.doWrite = function (data) {
Polling.prototype.doWrite.call(this);
XHR.prototype.doWrite = function (data) {
var headers = {
'Content-Type': 'text/plain; charset=UTF-8'
, 'Content-Length': Buffer.byteLength(data)
, 'Connection': 'Keep-Alive'
};
var origin = this.req.headers.origin
, headers = {
'Content-Type': 'text/plain; charset=UTF-8'
, 'Content-Length': data === undefined ? 0 : Buffer.byteLength(data)
, 'Connection': 'Keep-Alive'
};
if (origin) {
// https://developer.mozilla.org/En/HTTP_Access_Control
if (this.req.headers.origin) {
headers['Access-Control-Allow-Origin'] = '*';
if (this.req.headers.cookie) {
@@ -53,7 +49,6 @@ XHRPolling.prototype.doWrite = function (data) {
}
}
this.response.writeHead(200, headers);
this.response.write(data);
this.log.debug(this.name + ' writing', data);
this.res.writeHead(200, headers);
this.res.end(data);
};