openhab-cloud
openhab-cloud copied to clipboard
SSE subscriptions are not answered before first item change
I am trying to subscribe SSE events from openhab-cloud with my android app. It works fine for a locally running openHAB instance, but does not seem to connect when using openhab-cloud, regardless if it is installed locally or if I use myopenhab.
I can see that there is a difference in the response if I try to connect with curl. Local server replies with
GET /rest/events?topics=smarthome/items/VBatteryLevel/statechanged,smarthome/items/VCommand/command HTTP/1.1
Host: openhabianpi:8080
User-Agent: curl/7.58.0
Accept: /
HTTP/1.1 200 OK
X-Accel-Buffering: no
Content-Type: text/event-stream
Transfer-Encoding: chunked
Server: Jetty(9.4.12.v20180830)
openhab-cloud does not respond at all. It just leaves the connection open:
GET /rest/events?topics=smarthome/items/VBatteryLevel/statechanged,smarthome/items/VCommand/command HTTP/1.1
Host: localhost:3000
Authorization: Basic ******************
User-Agent: curl/7.58.0
Accept: /
The connection is actually open, and I do get a Content-Type header specifying the type text/event-stream as soon as the first item update is sent. This makes everything look okay if you subscribe to topics with frequent updates.
But according to the SSE specification, the server has to answer with a status code 200 and the Content-Type header directly when the request is received.
I have tried to access the locally running cloud instance without any reverse proxy in between, so this is not caused by a faulty proxy configuration, but seems to be a bug in the openhab-cloud code.
I experimented a little with this. Unfortunately I have no experience with nodejs. But it looks like the headers are sent back only if there is a response body. If I add
request.write(': ');
after
request.writeHead(data.responseStatusCode, data.responseStatusText, data.headers);
in the responseHeader event handling, everything works as expected.
Hi teams, has there been any fix for this? this still occurs.