Compare commits

...

4 Commits

Author SHA1 Message Date
James Coglan d1f2c2172d Bump version to 0.7.0. 2013-09-09 22:22:28 +01:00
James Coglan 0eb7d7173d Document the headers option to EventSource. 2013-08-24 11:52:47 +01:00
James Coglan 426e72786b Remove extra line break in EventSource headers. 2013-08-24 11:28:11 +01:00
James Coglan b126e31b81 Allow custom headers to be set on EventSource connections. 2013-08-24 11:21:05 +01:00
4 changed files with 25 additions and 7 deletions
+5
View File
@@ -1,3 +1,8 @@
### 0.7.0 / 2013-09-09
* Allow the server to send custom headers with EventSource responses
### 0.6.1 / 2013-07-05
* Add `ca` option to the client for specifying certificate authorities
+9 -3
View File
@@ -243,17 +243,23 @@ The `EventSource` object exposes the following properties:
When you initialize an EventSource with ` new EventSource()`, you can pass
configuration options after the `response` parameter. Available options are:
* <b>`headers`</b> is an object containing custom headers to be set on the
EventSource response.
* <b>`retry`</b> is a number that tells the client how long (in seconds) it
should wait after a dropped connection before attempting to reconnect.
* <b>`ping`</b> is a number that tells the server how often (in seconds) to
send 'ping' packets to the client to keep the connection open, to defeat
timeouts set by proxies. The client will ignore these messages.
For example, this creates a connection that pings every 15 seconds and is
retryable every 10 seconds if the connection is broken:
For example, this creates a connection that allows access from any origin, pings
every 15 seconds and is retryable every 10 seconds if the connection is broken:
```js
var es = new EventSource(request, response, {ping: 15, retry: 10});
var es = new EventSource(request, response, {
headers: {'Access-Control-Allow-Origin': '*'},
ping: 15,
retry: 10
});
```
You can send a ping message at any time by calling `es.ping()`. Unlike
+9 -2
View File
@@ -1,6 +1,7 @@
var Stream = require('stream').Stream,
util = require('util'),
driver = require('websocket-driver'),
Headers = require('websocket-driver/lib/websocket/driver/headers'),
API = require('./websocket/api'),
EventTarget = require('./websocket/api/event_target'),
Event = require('./websocket/api/event');
@@ -18,7 +19,12 @@ var EventSource = function(request, response, options) {
this.lastEventId = request.headers['last-event-id'] || '';
this.readyState = API.CONNECTING;
var self = this;
var headers = new Headers(),
self = this;
if (options.headers) {
for (var key in options.headers) headers.set(key, options.headers[key]);
}
if (!this._stream || !this._stream.writable) return;
process.nextTick(function() { self._open() });
@@ -30,7 +36,8 @@ var EventSource = function(request, response, options) {
'Content-Type: text/event-stream\r\n' +
'Cache-Control: no-cache, no-store\r\n' +
'Connection: close\r\n' +
'\r\n\r\n' +
headers.toString() +
'\r\n' +
'retry: ' + Math.floor(this._retry * 1000) + '\r\n\r\n';
this._write(handshake);
+2 -2
View File
@@ -5,10 +5,10 @@
, "keywords" : ["websocket", "eventsource"]
, "license" : "MIT"
, "version" : "0.6.1"
, "version" : "0.7.0"
, "engines" : {"node": ">=0.4.0"}
, "main" : "./lib/faye/websocket"
, "dependencies" : {"websocket-driver": ">=0.2.0"}
, "dependencies" : {"websocket-driver": ">=0.3.0"}
, "devDependencies" : {"jstest": "", "pace": ""}
, "scripts" : {"test": "jstest spec/runner.js"}