Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1f2c2172d | |||
| 0eb7d7173d | |||
| 426e72786b | |||
| b126e31b81 |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user