last-event-id2.py (643B)
1 ID_PERSISTS = 1 2 ID_RESETS_1 = 2 3 ID_RESETS_2 = 3 4 5 def main(request, response): 6 response.headers.set(b"Content-Type", b"text/event-stream") 7 try: 8 test_type = int(request.GET.first(b"type", ID_PERSISTS)) 9 except: 10 test_type = ID_PERSISTS 11 12 if test_type == ID_PERSISTS: 13 return b"id: 1\ndata: 1\n\ndata: 2\n\nid: 2\ndata:3\n\ndata:4\n\n" 14 15 elif test_type == ID_RESETS_1: 16 return b"id: 1\ndata: 1\n\nid:\ndata:2\n\ndata:3\n\n" 17 18 # empty id field without colon character (:) should also reset 19 elif test_type == ID_RESETS_2: 20 return b"id: 1\ndata: 1\n\nid\ndata:2\n\ndata:3\n\n" 21 22 else: 23 return b"data: invalid_test\n\n"