[Pkg-javascript-commits] [node-eventsource] 01/03: Imported Upstream version 0.2.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Jun 19 17:14:12 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-eventsource.

commit 4cf7afbf70186c005e100fbaf83925c02277bcb2
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Jun 19 19:07:50 2016 +0200

    Imported Upstream version 0.2.1
---
 .travis.yml                     |  8 ++--
 History.md                      | 85 ++++++++++++++++++++++-------------------
 README.md                       | 17 ++++++---
 example/eventsource-polyfill.js | 22 ++++++++---
 lib/eventsource.js              | 22 ++++++++---
 package.json                    | 17 +++++----
 6 files changed, 102 insertions(+), 69 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d7a05b7..3f8486b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,6 @@
 language: node_js
 
 node_js:
-  - 0.8.28
-  - 0.10.36
-  - 0.12.0
-  - 4.2.3
-  - 5.3.0
+  - 0.12.10
+  - 4.3.0
+  - 5.6.0
diff --git a/History.md b/History.md
index 5ae91d5..816a084 100644
--- a/History.md
+++ b/History.md
@@ -1,80 +1,87 @@
-# [Unreleased](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.6...v0.2.0)
+# [0.2.1](https://github.com/aslakhellesoy/eventsource/compare/v0.2.0...v0.2.1)
+
+* Fix `close()` for polyfill. ([#52](https://github.com/aslakhellesoy/eventsource/pull/52) brian-medendorp)
+* Add http/https proxy function. ([#46](https://github.com/aslakhellesoy/eventsource/pull/46) Eric Lu)
+* Fix reconnect for polyfill. Only disable reconnect when server status is 204. (Aslak Hellesøy).
+* Drop support for Node 0.10.x and older (Aslak Hellesøy).
+
+# [0.2.0](https://github.com/aslakhellesoy/eventsource/compare/v0.1.6...v0.2.0)
 
 * Renamed repository to `eventsource` (since it's not just Node, but also browser polyfill). (Aslak Hellesøy).
-* Compatibility with webpack/browserify. ([#44](https://github.com/aslakhellesoy/eventsource-node/pull/44) Adriano Raiano).
+* Compatibility with webpack/browserify. ([#44](https://github.com/aslakhellesoy/eventsource/pull/44) Adriano Raiano).
 
-# [0.1.6](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.5...v0.1.6)
+# [0.1.6](https://github.com/aslakhellesoy/eventsource/compare/v0.1.5...v0.1.6)
 
-* Ignore headers without a value. ([#41](https://github.com/aslakhellesoy/eventsource-node/issues/41), [#43](https://github.com/aslakhellesoy/eventsource-node/pull/43) Adriano Raiano)
+* Ignore headers without a value. ([#41](https://github.com/aslakhellesoy/eventsource/issues/41), [#43](https://github.com/aslakhellesoy/eventsource/pull/43) Adriano Raiano)
 
-# [0.1.5](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.4...v0.1.5)
+# [0.1.5](https://github.com/aslakhellesoy/eventsource/compare/v0.1.4...v0.1.5)
 
 * Refactor tests to support Node.js 0.12.0 and Io.js 1.1.0. (Aslak Hellesøy)
 
-# [0.1.4](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.3...master)
+# [0.1.4](https://github.com/aslakhellesoy/eventsource/compare/v0.1.3...master)
 
-* Bugfix: Added missing origin property. ([#39](https://github.com/aslakhellesoy/eventsource-node/pull/39), [#38](https://github.com/aslakhellesoy/eventsource-node/issues/38) Arnout Kazemier)
-* Expose `status` property on `error` events. ([#40](https://github.com/aslakhellesoy/eventsource-node/pull/40) Adriano Raiano)
+* Bugfix: Added missing origin property. ([#39](https://github.com/aslakhellesoy/eventsource/pull/39), [#38](https://github.com/aslakhellesoy/eventsource/issues/38) Arnout Kazemier)
+* Expose `status` property on `error` events. ([#40](https://github.com/aslakhellesoy/eventsource/pull/40) Adriano Raiano)
 
-# [0.1.3](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.2...v0.1.3)
+# [0.1.3](https://github.com/aslakhellesoy/eventsource/compare/v0.1.2...v0.1.3)
 
-* Bugfix: Made message properties enumerable. ([#37](https://github.com/aslakhellesoy/eventsource-node/pull/37) Golo Roden)
+* Bugfix: Made message properties enumerable. ([#37](https://github.com/aslakhellesoy/eventsource/pull/37) Golo Roden)
 
-# [0.1.2](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.1...v0.1.2)
+# [0.1.2](https://github.com/aslakhellesoy/eventsource/compare/v0.1.1...v0.1.2)
 
-* Bugfix: Blank lines not read. ([#35](https://github.com/aslakhellesoy/eventsource-node/issues/35), [#36](https://github.com/aslakhellesoy/eventsource-node/pull/36) Lesterpig)
+* Bugfix: Blank lines not read. ([#35](https://github.com/aslakhellesoy/eventsource/issues/35), [#36](https://github.com/aslakhellesoy/eventsource/pull/36) Lesterpig)
 
-# [0.1.1](https://github.com/aslakhellesoy/eventsource-node/compare/v0.1.0...v0.1.1)
+# [0.1.1](https://github.com/aslakhellesoy/eventsource/compare/v0.1.0...v0.1.1)
 
-* Bugfix: Fix message type. ([#33](https://github.com/aslakhellesoy/eventsource-node/pull/33) Romain Gauthier)
+* Bugfix: Fix message type. ([#33](https://github.com/aslakhellesoy/eventsource/pull/33) Romain Gauthier)
 
-# [0.1.0](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.10...v0.1.0)
+# [0.1.0](https://github.com/aslakhellesoy/eventsource/compare/v0.0.10...v0.1.0)
 
-* Bugfix: High CPU usage by replacing Jison with port of WebKit's parser. ([#25](https://github.com/aslakhellesoy/eventsource-node/issues/25), [#32](https://github.com/aslakhellesoy/eventsource-node/pull/32), [#18](https://github.com/aslakhellesoy/eventsource-node/issues/18) qqueue)
+* Bugfix: High CPU usage by replacing Jison with port of WebKit's parser. ([#25](https://github.com/aslakhellesoy/eventsource/issues/25), [#32](https://github.com/aslakhellesoy/eventsource/pull/32), [#18](https://github.com/aslakhellesoy/eventsource/issues/18) qqueue)
 * Reformatted all code to 2 spaces.
 
-# [0.0.10](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.9...v0.0.10)
+# [0.0.10](https://github.com/aslakhellesoy/eventsource/compare/v0.0.9...v0.0.10)
 
-* Provide `Event` argument on `open` and `error` event ([#30](https://github.com/aslakhellesoy/eventsource-node/issues/30), [#31](https://github.com/aslakhellesoy/eventsource-node/pull/31) Donghwan Kim)
-* Expose `lastEventId` on messages. ([#28](https://github.com/aslakhellesoy/eventsource-node/pull/28) mbieser)
+* Provide `Event` argument on `open` and `error` event ([#30](https://github.com/aslakhellesoy/eventsource/issues/30), [#31](https://github.com/aslakhellesoy/eventsource/pull/31) Donghwan Kim)
+* Expose `lastEventId` on messages. ([#28](https://github.com/aslakhellesoy/eventsource/pull/28) mbieser)
 
-# [0.0.9](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.8...v0.0.9)
+# [0.0.9](https://github.com/aslakhellesoy/eventsource/compare/v0.0.8...v0.0.9)
 
-* Bugfix: old "last-event-id" used on reconnect ([#27](https://github.com/aslakhellesoy/eventsource-node/pull/27) Aslak Hellesøy)
+* Bugfix: old "last-event-id" used on reconnect ([#27](https://github.com/aslakhellesoy/eventsource/pull/27) Aslak Hellesøy)
 
-# [0.0.8](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.7...v0.0.8)
+# [0.0.8](https://github.com/aslakhellesoy/eventsource/compare/v0.0.7...v0.0.8)
 
-* Bugfix: EventSource still reconnected when closed ([#24](https://github.com/aslakhellesoy/eventsource-node/pull/24) FrozenCow)
+* Bugfix: EventSource still reconnected when closed ([#24](https://github.com/aslakhellesoy/eventsource/pull/24) FrozenCow)
 * Allow unauthorized HTTPS connections by setting `rejectUnauthorized` to false. (Aslak Hellesøy)
 
-# [0.0.7](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.6...v0.0.7)
+# [0.0.7](https://github.com/aslakhellesoy/eventsource/compare/v0.0.6...v0.0.7)
 
-* Explicitly raise an error when server returns http 403 and don't continue ([#20](https://github.com/aslakhellesoy/eventsource-node/pull/20) Scott Moak)
-* Added ability to send custom http headers to server ([#21](https://github.com/aslakhellesoy/eventsource-node/pull/21), [#9](https://github.com/aslakhellesoy/eventsource-node/issues/9) Scott Moak)
-* Fix Unicode support to cope with Javascript Unicode size limitations ([#23](https://github.com/aslakhellesoy/eventsource-node/pull/23), [#22](https://github.com/aslakhellesoy/eventsource-node/issues/22) Devon Adkisson)
-* Graceful handling of parse errors ([#19](https://github.com/aslakhellesoy/eventsource-node/issues/19) Aslak Hellesøy)
+* Explicitly raise an error when server returns http 403 and don't continue ([#20](https://github.com/aslakhellesoy/eventsource/pull/20) Scott Moak)
+* Added ability to send custom http headers to server ([#21](https://github.com/aslakhellesoy/eventsource/pull/21), [#9](https://github.com/aslakhellesoy/eventsource/issues/9) Scott Moak)
+* Fix Unicode support to cope with Javascript Unicode size limitations ([#23](https://github.com/aslakhellesoy/eventsource/pull/23), [#22](https://github.com/aslakhellesoy/eventsource/issues/22) Devon Adkisson)
+* Graceful handling of parse errors ([#19](https://github.com/aslakhellesoy/eventsource/issues/19) Aslak Hellesøy)
 * Switched from testing with Nodeunit to Mocha (Aslak Hellesøy)
 
-# [0.0.6](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.5...v0.0.6)
+# [0.0.6](https://github.com/aslakhellesoy/eventsource/compare/v0.0.5...v0.0.6)
 
-* Add Accept: text/event-stream header ([#17](https://github.com/aslakhellesoy/eventsource-node/pull/17) William Wicks)
+* Add Accept: text/event-stream header ([#17](https://github.com/aslakhellesoy/eventsource/pull/17) William Wicks)
 
-# [0.0.5](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.4...v0.0.5)
+# [0.0.5](https://github.com/aslakhellesoy/eventsource/compare/v0.0.4...v0.0.5)
 
-* Add no-cache and https support ([#10](https://github.com/aslakhellesoy/eventsource-node/pull/10) Einar Otto Stangvik)
-* Ensure that Last-Event-ID is sent to the server for reconnects, as defined in the spec ([#8](https://github.com/aslakhellesoy/eventsource-node/pull/8) Einar Otto Stangvik)
-* Verify that CR and CRLF are accepted alongside LF ([#7](https://github.com/aslakhellesoy/eventsource-node/pull/7) Einar Otto Stangvik)
-* Emit 'open' event ([#4](https://github.com/aslakhellesoy/eventsource-node/issues/4) Einar Otto Stangvik)
+* Add no-cache and https support ([#10](https://github.com/aslakhellesoy/eventsource/pull/10) Einar Otto Stangvik)
+* Ensure that Last-Event-ID is sent to the server for reconnects, as defined in the spec ([#8](https://github.com/aslakhellesoy/eventsource/pull/8) Einar Otto Stangvik)
+* Verify that CR and CRLF are accepted alongside LF ([#7](https://github.com/aslakhellesoy/eventsource/pull/7) Einar Otto Stangvik)
+* Emit 'open' event ([#4](https://github.com/aslakhellesoy/eventsource/issues/4) Einar Otto Stangvik)
 
-# [0.0.4](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.3...v0.0.4)
+# [0.0.4](https://github.com/aslakhellesoy/eventsource/compare/v0.0.3...v0.0.4)
 
 * Automatic reconnect every second if the server is down. Reconnect interval can be set with `reconnectInterval` (not in W3C spec). (Aslak Hellesøy)
 
-# [0.0.3](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.2...v0.0.3)
+# [0.0.3](https://github.com/aslakhellesoy/eventsource/compare/v0.0.2...v0.0.3)
 
-* Jison based eventstream parser ([#2](https://github.com/aslakhellesoy/eventsource-node/pull/2) Einar Otto Stangvik)
+* Jison based eventstream parser ([#2](https://github.com/aslakhellesoy/eventsource/pull/2) Einar Otto Stangvik)
 
-# [0.0.2](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.1...v0.0.2)
+# [0.0.2](https://github.com/aslakhellesoy/eventsource/compare/v0.0.1...v0.0.2)
 
 * Use native EventListener (Aslak Hellesøy)
 
diff --git a/README.md b/README.md
index a8ea8d2..884f06b 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-# EventSource [![Build Status](https://secure.travis-ci.org/aslakhellesoy/eventsource-node.png)](http://travis-ci.org/aslakhellesoy/eventsource-node) [![Dependencies](https://david-dm.org/aslakhellesoy/eventsource-node.png)](https://david-dm.org/aslakhellesoy/eventsource-node) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/aslakhellesoy/eventsource-node/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
-
+# EventSource [![Build Status](https://secure.travis-ci.org/aslakhellesoy/eventsource.svg)](http://travis-ci.org/aslakhellesoy/eventsource) [![Dependencies](https://david-dm.org/aslakhellesoy/eventsource.svg)](https://david-dm.org/aslakhellesoy/eventsource)
 
 [![NPM](https://nodei.co/npm/eventsource.png?stars&downloads)](https://nodei.co/npm/eventsource/)
 [![NPM](https://nodei.co/npm-dl/eventsource.png)](https://nodei.co/npm/eventsource/)
@@ -17,9 +16,9 @@ You can use it with Node.js or as a browser polyfill for
 
     npm install
     node ./example/sse-server.js
-    node ./example/sse-client.js  (Node.js client)
-    open http://localhost:8080     (Browser client - both native and polyfill)
-    curl http://localhost:8080/sse (Enjoy the simplicity of SSE)
+    node ./example/sse-client.js    # Node.js client
+    open http://localhost:8080      # Browser client - both native and polyfill
+    curl http://localhost:8080/sse  # Enjoy the simplicity of SSE)
 
 ## Browser Polyfill
 
@@ -78,3 +77,11 @@ es.onerror = function (err) {
   }
 };
 ```
+
+### HTTP/HTTPS proxy
+
+You can define a `proxy` option for the HTTP request to be used. This is typically useful if you are behind a corporate firewall.
+
+```javascript
+var es = new EventSource(url, { proxy: 'http://your.proxy.com' });
+```
diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js
index 7d0da2b..53bfe58 100644
--- a/example/eventsource-polyfill.js
+++ b/example/eventsource-polyfill.js
@@ -67,7 +67,7 @@
 	 * Creates a new EventSource object
 	 *
 	 * @param {String} url the URL to which to connect
-	 * @param {Object} eventSourceInitDict extra init params. See README for details.
+	 * @param {Object} [eventSourceInitDict] extra init params. See README for details.
 	 * @api public
 	 **/
 	function EventSource(url, eventSourceInitDict) {
@@ -86,11 +86,9 @@
 
 	  var self = this;
 	  self.reconnectInterval = 1000;
-	  var connectPending = false;
 
 	  function onConnectionClosed() {
-	    if (connectPending || readyState === EventSource.CLOSED) return;
-	    connectPending = true;
+	    if (readyState === EventSource.CLOSED) return;
 	    readyState = EventSource.CONNECTING;
 	    _emit('error', new Event('error'));
 
@@ -122,7 +120,6 @@
 	  var reconnectUrl = null;
 
 	  function connect() {
-	    connectPending = false;
 
 	    var options = parse(url);
 	    var isSecure = options.protocol == 'https:';
@@ -139,6 +136,17 @@
 
 	    options.rejectUnauthorized = !(eventSourceInitDict && eventSourceInitDict.rejectUnauthorized == false);
 
+	    // If specify http proxy, make the request to sent to the proxy server,
+	    // and include the original url in path and Host headers
+	    if (eventSourceInitDict && eventSourceInitDict.proxy) {
+	        var proxy = parse(eventSourceInitDict.proxy);
+	        options.path = url;
+	        options.headers.Host = options.host;
+	        options.hostname = proxy.hostname;
+	        options.host = proxy.host;
+	        options.port = proxy.port;
+	    }
+
 	    req = (isSecure ? https : http).request(options, function (res) {
 	      // Handle HTTP redirects
 	      if (res.statusCode == 301 || res.statusCode == 307) {
@@ -155,7 +163,8 @@
 
 	      if (res.statusCode !== 200) {
 	        _emit('error', new Event('error', {status: res.statusCode}));
-	        return self.close();
+	        if (res.statusCode == 204) return self.close();
+	        return
 	      }
 
 	      readyState = EventSource.OPEN;
@@ -231,6 +240,7 @@
 	    if (readyState == EventSource.CLOSED) return;
 	    readyState = EventSource.CLOSED;
 	    if (req.abort) req.abort();
+	    if (req.xhr && req.xhr.abort) req.xhr.abort();
 	  };
 
 	  function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
diff --git a/lib/eventsource.js b/lib/eventsource.js
index b93eb5e..7fb0a8b 100644
--- a/lib/eventsource.js
+++ b/lib/eventsource.js
@@ -13,7 +13,7 @@ function isPlainObject(obj) {
  * Creates a new EventSource object
  *
  * @param {String} url the URL to which to connect
- * @param {Object} eventSourceInitDict extra init params. See README for details.
+ * @param {Object} [eventSourceInitDict] extra init params. See README for details.
  * @api public
  **/
 function EventSource(url, eventSourceInitDict) {
@@ -32,11 +32,9 @@ function EventSource(url, eventSourceInitDict) {
 
   var self = this;
   self.reconnectInterval = 1000;
-  var connectPending = false;
 
   function onConnectionClosed() {
-    if (connectPending || readyState === EventSource.CLOSED) return;
-    connectPending = true;
+    if (readyState === EventSource.CLOSED) return;
     readyState = EventSource.CONNECTING;
     _emit('error', new Event('error'));
 
@@ -68,7 +66,6 @@ function EventSource(url, eventSourceInitDict) {
   var reconnectUrl = null;
 
   function connect() {
-    connectPending = false;
 
     var options = parse(url);
     var isSecure = options.protocol == 'https:';
@@ -85,6 +82,17 @@ function EventSource(url, eventSourceInitDict) {
 
     options.rejectUnauthorized = !(eventSourceInitDict && eventSourceInitDict.rejectUnauthorized == false);
 
+    // If specify http proxy, make the request to sent to the proxy server,
+    // and include the original url in path and Host headers
+    if (eventSourceInitDict && eventSourceInitDict.proxy) {
+        var proxy = parse(eventSourceInitDict.proxy);
+        options.path = url;
+        options.headers.Host = options.host;
+        options.hostname = proxy.hostname;
+        options.host = proxy.host;
+        options.port = proxy.port;
+    }
+
     req = (isSecure ? https : http).request(options, function (res) {
       // Handle HTTP redirects
       if (res.statusCode == 301 || res.statusCode == 307) {
@@ -101,7 +109,8 @@ function EventSource(url, eventSourceInitDict) {
 
       if (res.statusCode !== 200) {
         _emit('error', new Event('error', {status: res.statusCode}));
-        return self.close();
+        if (res.statusCode == 204) return self.close();
+        return
       }
 
       readyState = EventSource.OPEN;
@@ -177,6 +186,7 @@ function EventSource(url, eventSourceInitDict) {
     if (readyState == EventSource.CLOSED) return;
     readyState = EventSource.CLOSED;
     if (req.abort) req.abort();
+    if (req.xhr && req.xhr.abort) req.xhr.abort();
   };
 
   function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
diff --git a/package.json b/package.json
index 60add23..243328b 100644
--- a/package.json
+++ b/package.json
@@ -1,21 +1,22 @@
 {
   "name": "eventsource",
-  "version": "0.2.0",
-  "description": "W3C compliant EventSource client for Node.js",
+  "version": "0.2.1",
+  "description": "W3C compliant EventSource client for Node.js and browser (polyfill)",
   "keywords": [
     "eventsource",
     "http",
     "streaming",
-    "sse"
+    "sse",
+    "polyfill"
   ],
-  "homepage": "http://github.com/aslakhellesoy/eventsource-node",
+  "homepage": "http://github.com/aslakhellesoy/eventsource",
   "author": "Aslak Hellesøy <aslak.hellesoy at gmail.com>",
   "repository": {
     "type": "git",
-    "url": "git://github.com/aslakhellesoy/eventsource-node.git"
+    "url": "git://github.com/aslakhellesoy/eventsource.git"
   },
   "bugs": {
-    "url": "http://github.com/aslakhellesoy/eventsource-node/issues"
+    "url": "http://github.com/aslakhellesoy/eventsource/issues"
   },
   "directories": {
     "lib": "./lib"
@@ -25,7 +26,7 @@
   "licenses": [
     {
       "type": "MIT",
-      "url": "http://github.com/aslakhellesoy/eventsource-node/raw/master/LICENSE"
+      "url": "http://github.com/aslakhellesoy/eventsource/raw/master/LICENSE"
     }
   ],
   "devDependencies": {
@@ -33,7 +34,7 @@
     "mocha": "^2.4.5",
     "serve-static": "^1.10.2",
     "sse": "^0.0.6",
-    "webpack": "^1.12.13"
+    "webpack": "^1.12.14"
   },
   "scripts": {
     "test": "mocha --reporter spec",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-eventsource.git



More information about the Pkg-javascript-commits mailing list