From 969cba6332121a0de99b8298bff28e4a716ae010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Arranz?= Date: Thu, 24 Jan 2019 14:47:14 +0100 Subject: [PATCH 1/3] Return a 204 error code instead of a 404 error code when the eventsource does not exist as per standard --- logic.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/logic.js b/logic.js index cb0abcc..56c169c 100644 --- a/logic.js +++ b/logic.js @@ -190,7 +190,8 @@ exports.eventsource = function eventsource(req, res) { res.header('Access-Control-Allow-Origin', origin); } if (connection == null) { - return res.sendStatus(404); + // https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events-intro + return res.sendStatus(204); } res.header('Cache-Control', 'no-cache'); From cce0f8dcd00d484883928559fe670506fa72d37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Arranz?= Date: Tue, 18 Jun 2019 12:27:31 +0200 Subject: [PATCH 2/3] Configure eventsource to stop trying to reconnect after 10 retries --- logic.js | 1 + 1 file changed, 1 insertion(+) diff --git a/logic.js b/logic.js index 56c169c..5920a9a 100644 --- a/logic.js +++ b/logic.js @@ -220,6 +220,7 @@ exports.eventsource = function eventsource(req, res) { res.header('Content-Type', 'text/event-stream'); res.write('event: init\n'); + res.write('retry: 10\n'); res.write('data: ' + JSON.stringify({ id: connection.id, url: build_absolute_url(req, '/eventsource/' + connection.id) From 61d5ec59605ecd180e7f3490049e3850078f80e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Arranz?= Date: Tue, 18 Jun 2019 12:38:40 +0200 Subject: [PATCH 3/3] Update tests to require a 204 status code --- test/ngsiproxySpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ngsiproxySpec.js b/test/ngsiproxySpec.js index d7b35fe..b5651c8 100644 --- a/test/ngsiproxySpec.js +++ b/test/ngsiproxySpec.js @@ -94,13 +94,13 @@ describe('ngsi-proxy server', () => { }); }); - it('404 when trying to connect to an inexistent eventsource', (done) => { + it('204 when trying to connect to an inexistent eventsource', (done) => { request.get('http://localhost:4321/eventsource/6d3ab640-345c-11e8-aee8-4fe128ae5aa3', (error, response, body) => { expect(error).toBe(null); expect(response.headers['access-control-allow-origin']).toBe(undefined); expect(response.headers['access-control-allow-headers']).toBe(undefined); expect(response.headers['access-control-expose-headers']).toBe(undefined); - expect(response.statusCode).toBe(404); + expect(response.statusCode).toBe(204); done(); }); });