Skip to content

Commit

Permalink
Merge pull request #10 from aarranz/fix/eventsource-notfound-status-code
Browse files Browse the repository at this point in the history
Fix returned eventsource status code when not found
  • Loading branch information
aarranz authored Jun 18, 2019
2 parents a538688 + 61d5ec5 commit ddb92a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -219,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)
Expand Down
4 changes: 2 additions & 2 deletions test/ngsiproxySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit ddb92a1

Please sign in to comment.