Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSE subscriptions are not answered before first item change #258

Open
vbier opened this issue May 20, 2019 · 2 comments
Open

SSE subscriptions are not answered before first item change #258

vbier opened this issue May 20, 2019 · 2 comments

Comments

@vbier
Copy link

vbier commented May 20, 2019

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.

@vbier
Copy link
Author

vbier commented May 20, 2019

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.

@dastrix80
Copy link

Hi teams, has there been any fix for this? this still occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants