[web-devel] WAI or Snap and the EventSource API

Mathias Biilmann Christensen mathiasch at gmail.com
Sat Aug 27 10:37:35 CEST 2011


Hi there,

I've been experimenting a bit with the new EventSource API (
http://hacks.mozilla.org/2011/06/a-wall-powered-by-eventsource-and-server-sent-events/
).

EventSource looks like a much nicer alternative to WebSockets in all the
cases where the connection doesn't really need to be bi-directional (ajax
request to push to the server, Event Source to push to the client). It
doesn't require a new protocol and should be trivial to pass through HTTP
aware load balancers, cache proxies and so on.

Have been trying to get either Snap or Warp to serve up an EventSource
endpoint, but so far I'm stuck at not being able to get any of them to
actually write to the response body before the request is all over.

Here's some example code:

Snap based: https://gist.github.com/1174102
WAI/Warp based: https://gist.github.com/1174632

The code is mostly the same apart from the glue to the web server. In both
cases I'm trying a silly enumerator that gets messages from the keyboard and
pass them to the iterator.

It all compiles and kinda works, but nothing gets written to the response
before I end the enumeration with "q".

Any hints on what I'm doing wrong? Or any example code for controlling
writes to the response body during a long request?

Cheers,
Mathias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110827/e0b95373/attachment.htm>


More information about the web-devel mailing list