summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/eventsource/resources/message2.py
blob: ce339d927e3133339123711e5c9cef8c4e75b353 (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
25
26
27
28
29
30
31
32
33
34
35
import time

def main(request, response):
    response.headers.set('Content-Type', 'text/event-stream')
    response.headers.set('Cache-Control', 'no-cache')

    response.explicit_flush = True
    response.write_status_headers()

    while True:
        response.writer.write("data:msg")
        response.writer.write("\n")
        response.writer.write("data: msg")
        response.writer.write("\n\n")

        response.writer.write(":")
        response.writer.write("\n")

        response.writer.write("falsefield:msg")
        response.writer.write("\n\n")

        response.writer.write("falsefield:msg")
        response.writer.write("\n")

        response.writer.write("Data:data")
        response.writer.write("\n\n")

        response.writer.write("data")
        response.writer.write("\n\n")

        response.writer.write("data:end")
        response.writer.write("\n\n")

        response.writer.flush()
        time.sleep(2)