Re: Server-Sent Events
- Posted by ghaberek (admin) May 08, 2017
- 3606 views
CraigWelch said...
--******************************************** --* function test_progress() * --******************************************** function test_progress() --puts(1,"Cache-Control: no-cache") -- This header would prevent the function from working. puts(1,"Content-Type: text/event-stream\n\n") for i = 1 to 100 do sleep(0.1) puts(1, sprintf("data: %d \n\n", i)) -- must have the two newlines flush(1) end for puts(1, "Status: 415 OK") return {"Finished test"} end function
I think the problem is that you're not ending your Cache-Control header with the expected "\r\n" terminator.
So this code:
puts(1,"Cache-Control: no-cache") puts(1,"Content-Type: text/event-stream\n\n")
Will output this text, which is incorrect:
Cache-Control: no-cacheContent-Type: text/event-stream\n\n
The correct code would look like this:
puts(1,"Cache-Control: no-cache\r\n") puts(1,"Content-Type: text/event-stream\r\n") puts(1,"\r\n")
And the output looks like this:
Cache-Control: no-cache\r\n Content-Type: text/event-stream\r\n \r\n
See: http://stackoverflow.com/a/5757349/2300395
-Greg