4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
12 var HTTPPolling = require('./http-polling');
15 * Export the constructor.
18 exports = module.exports = XHRPolling;
21 * Ajax polling transport.
26 function XHRPolling (mng, data, req) {
27 HTTPPolling.call(this, mng, data, req);
31 * Inherits from Transport.
34 XHRPolling.prototype.__proto__ = HTTPPolling.prototype;
42 XHRPolling.prototype.name = 'xhr-polling';
45 * Frames data prior to write.
50 XHRPolling.prototype.doWrite = function (data) {
51 HTTPPolling.prototype.doWrite.call(this);
53 var origin = this.req.headers.origin
55 'Content-Type': 'text/plain; charset=UTF-8'
56 , 'Content-Length': data === undefined ? 0 : Buffer.byteLength(data)
57 , 'Connection': 'Keep-Alive'
61 // https://developer.mozilla.org/En/HTTP_Access_Control
62 headers['Access-Control-Allow-Origin'] = origin;
63 headers['Access-Control-Allow-Credentials'] = 'true';
66 this.response.writeHead(200, headers);
67 this.response.write(data);
68 this.log.debug(this.name + ' writing', data);