From 50cb68fe073146ad95f1af36918748a91402ffd1 Mon Sep 17 00:00:00 2001 From: LaunchDarklyCI Date: Tue, 26 Jan 2021 00:04:19 +0000 Subject: [PATCH] Releasing version 1.4.0 --- CHANGELOG.md | 4 +++ example/eventsource-polyfill.js | 51 +++++++++++++++++++++++++++++---- package.json | 2 +- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1180812..f6a017d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this package will be documented in this file. +## [1.4.0] - 2021-01-25 +### Added: +- Added `readTimeoutMillis` option for automatically dropping and restarting a connection if too much time has elapsed without receiving any data. + ## [1.3.1] - 2020-06-29 ### Fixed: - Incorporated [a fix](https://github.com/EventSource/eventsource/pull/130) from the upstream repository that avoids unnecessary delays when parsing a long message that is received in multiple chunks. diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js index 5d5d1bb..6ce25a0 100644 --- a/example/eventsource-polyfill.js +++ b/example/eventsource-polyfill.js @@ -3278,6 +3278,7 @@ function EventEmitter() { EventEmitter.init.call(this); } module.exports = EventEmitter; +module.exports.once = once; // Backwards-compat with node 0.10.x EventEmitter.EventEmitter = EventEmitter; @@ -3669,6 +3670,35 @@ function unwrapListeners(arr) { return ret; } +function once(emitter, name) { + return new Promise(function (resolve, reject) { + function eventListener() { + if (errorListener !== undefined) { + emitter.removeListener('error', errorListener); + } + resolve([].slice.call(arguments)); + }; + var errorListener; + + // Adding an error listener is not optional because + // if an error is thrown on an event emitter we cannot + // guarantee that the actual event we are waiting will + // be fired. The result could be a silent way to create + // memory or file descriptor leaks, which is something + // we should avoid. + if (name !== 'error') { + errorListener = function errorListener(err) { + emitter.removeListener(name, eventListener); + reject(err); + }; + + emitter.once('error', errorListener); + } + + emitter.once(name, eventListener); + }); +} + /***/ }), /* 10 */ @@ -6668,6 +6698,7 @@ function EventSource (url, eventSourceInitDict) { var buf var startingPos = 0 var startingFieldLength = -1 + res.on('data', function (chunk) { buf = buf ? Buffer.concat([buf, chunk]) : chunk if (isFirst && hasBom(buf)) { @@ -6726,6 +6757,10 @@ function EventSource (url, eventSourceInitDict) { }) }) + if (config.readTimeoutMillis) { + req.setTimeout(config.readTimeoutMillis) + } + if (config.body) { req.write(config.body) } @@ -6734,6 +6769,11 @@ function EventSource (url, eventSourceInitDict) { failed({ message: err.message }) }) + req.on('timeout', function () { + failed({ message: 'Read timeout, received no data in ' + config.readTimeoutMillis + + 'ms, assuming connection is dead' }) + }) + if (req.setNoDelay) req.setNoDelay(true) req.end() } @@ -7100,9 +7140,7 @@ function fromByteArray (uint8) { // go through the array every three bytes, we'll deal with trailing stuff later for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk( - uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) - )) + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) } // pad the end with zeros, but make sure to not forget the extra bytes @@ -7131,6 +7169,7 @@ function fromByteArray (uint8) { /* 24 */ /***/ (function(module, exports) { +/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = (nBytes * 8) - mLen - 1 @@ -7882,7 +7921,7 @@ function encode(input) { * @api public */ function querystring(query) { - var parser = /([^=?&]+)=?([^&]*)/g + var parser = /([^=?#&]+)=?([^&]*)/g , result = {} , part; @@ -7937,8 +7976,8 @@ function querystringify(obj, prefix) { value = ''; } - key = encodeURIComponent(key); - value = encodeURIComponent(value); + key = encode(key); + value = encode(value); // // If we failed to encode the strings, we should bail out as we don't diff --git a/package.json b/package.json index 91a42c7..9ebfbd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "launchdarkly-eventsource", - "version": "1.3.1", + "version": "1.4.0", "description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)", "keywords": [ "eventsource",