annotate website/src/examples/sse_push.html.luan @ 1738:9713f7fd50b3

server-sent events
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2022 19:23:53 -0600
parents
children 3e9f26404433
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1738
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Io = require "luan:Io.luan"
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local Http = require "luan:http/Http.luan"
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Logging = require "luan:logging/Logging.luan"
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local logger = Logging.logger "init"
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 return function()
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local request = Http.request
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local message = request.parameters.message
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 if message ~= nil then
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local url = request.url()
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 Http.push(url,message)
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 end
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 Io.stdout = Http.response.text_writer()
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 %>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 <!doctype html>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <html>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <body>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <h1>push server-sent events</h1>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <form method=post>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <p><textarea name=message></textarea></p>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <p><input type=submit></p>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 </form>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 </body>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 </html>
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 <%
9713f7fd50b3 server-sent events
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end