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

Searching actual working SSE example (#1008 does not work for me) #1424

Closed
lwe opened this issue Feb 13, 2014 · 4 comments
Closed

Searching actual working SSE example (#1008 does not work for me) #1424

lwe opened this issue Feb 13, 2014 · 4 comments
Assignees
Labels
documentation Non-code related changes feature New functionality or improvement
Milestone

Comments

@lwe
Copy link

lwe commented Feb 13, 2014

Recently started with Hapi and was trying to get server sent events working, as I was running into troubles I found #1008 - but the example in there did not work for me. In fact I got a very strange behavior, because inspecting the result with curl seemed to look the same, but in neither Chrome nor Firefox I got the onmessage events.

To demonstrate the behavior I've written a sample server in both Hapi and plain node.js (might add that plain node.js works): https://gist.github.com/lwe/8982052 The output from curl is for both versions actually (and funnily) enough the same.

Start the server by running either node hapi.js or node plain.js and then go to http://localhost:8000/hello, then check the debug console for any output.

OK: plain.js in Chrome

plain_js

Looks good abcdef is printed on the screen multiple times, also in the Network tab it looks like

screenshot 2014-02-13 20 39 47

NOK: hapi.js in Chrome

hapi_js

In Network tab it is marked as pending, it looks like the stream is not flushed or something.

screenshot 2014-02-13 20 39 36

Summary

I get the same behavior in Firefox actually. However, when checking the output with curl I do get the exactly same (!) output for both the Hapi and plain node variant, I've no idea why neither Chrome nor Firefox are getting the onmessage calls.

Any help is appreciated, thanks in advance.

@lwe
Copy link
Author

lwe commented Feb 13, 2014

Minor update, but when working with request.raw.res instead of the reply() method it works as expected, though I somehow suppose I haven't yet understood how reply() actually works...

// replacing reply(channel)...
request.raw.res.writeHead(200, { 'content-type': 'text/event-stream; charset=utf-8', 'connection': 'keep-alive', 'cache-control': 'no-cache' });
channel.pipe(request.raw.res);

@hueniverse hueniverse added this to the 2.4.0 milestone Feb 14, 2014
@hueniverse hueniverse self-assigned this Feb 14, 2014
@hueniverse
Copy link
Contributor

The problem with your example was missing header('Content-Encoding', 'identity') to prevent the server from gzipping the data. This looks like a browser bug to me but I don't know anything about this. I added a new example for server sent events, as well as a new request 'disconnect' event to remove the need to interact with the raw constructs.

@lwe
Copy link
Author

lwe commented Feb 14, 2014

✨ thanks a lot for the fast response.

Actually, I tried setting Content-Encoding: identity header, but probably in a different combination, because it did not work for me. Yes, the funny thing is that the "pure" node.js variant still uses Content-Encoding: chunked, somehow the browser does not continue reading the stream, very weird - but well it works now.

PS: Very, very nice work on Hapi and all the related modules.

@Marsup Marsup added documentation Non-code related changes feature New functionality or improvement and removed example labels Sep 20, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Non-code related changes feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants