Hi,

I'm trying to send updates to my client using an Event-Stream.

My code for updates is:

void statusUpdate(HTTPServerRequest req, HTTPServerResponse res){                                                                                            
    res.contentType = "text/event-stream";                                                                                                                   
    res.headers["Cache-Control"] = "no-cache";                                                                                                               
    import std.random : uniform;                                                                                                                             
    res.writeBody(format("This is a test...%s", uniform(1.0,1000.0)), "text/event-stream");                                                                  
}

And the code to handle it on the client is:

    script(type="text/javascript")                                                                                                                           
        if(!!window.EventSource){                                                                                                                            
            var source = new EventSource("/admin/statusUpdate");                                                                                             
            source.addEventListener('message', displayPoll, false);                                                                                          
            console.log("Listening to /admin/statusUpdate...");                                                                                              
            console.log("Source: " + source);                                                                                                                
                                                                                                                                                             
        }                                                                                                                                                    
                                                                                                                                                             
        function displayPoll(event){                                                                                                                         
                var html = event.data;                                                                                                                       
                var log = document.getElementById("serverStatus");                                                                                           
                if(log){                                                                                                                                     
                    log.innerHTML += "poll: " + html + "<br>";                                                                                               
                }                                                                                                                                            
            }

On the client, I can see that the requests are received every 3 or so seconds.
However, nothing is ever in the body of these requests, its just headers.

Also, the displayPoll function never seems to get called, I'm not sure as to why.
Maybe I'm constructing this thing all wrong?
Or maybe I'm using vibes res.writeBody() wrong?

Thanks for any help on this, been wrecking my brain on it all day!