blob: 80a247d5974bf9351318073ad017fcaed4af3e8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
def main(request, response):
name = "recon_fail_" + request.GET.first("id")
headers = [("Content-Type", "text/event-stream")]
cookie = request.cookies.first(name, None)
state = cookie.value if cookie is not None else None
if state == 'opened':
status = (200, "RECONNECT")
response.set_cookie(name, "reconnected");
body = "data: reconnected\n\n";
elif state == 'reconnected':
status = (204, "NO CONTENT (CLOSE)")
response.delete_cookie(name);
body = "data: closed\n\n" # Will never get through
else:
status = (200, "OPEN");
response.set_cookie(name, "opened");
body = "retry: 2\ndata: opened\n\n";
return status, headers, body
|