summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/eventsource/resources/reconnect-fail.py
blob: 12b07700cd0d29ac5988ba0b3bd77db276e2289f (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 = b"recon_fail_" + request.GET.first(b"id")

    headers = [(b"Content-Type", b"text/event-stream")]
    cookie = request.cookies.first(name, None)
    state = cookie.value if cookie is not None else None

    if state == b'opened':
        status = (200, b"RECONNECT")
        response.set_cookie(name, b"reconnected");
        body = b"data: reconnected\n\n";

    elif state == b'reconnected':
        status = (204, b"NO CONTENT (CLOSE)")
        response.delete_cookie(name);
        body = b"data: closed\n\n" # Will never get through

    else:
        status = (200, b"OPEN");
        response.set_cookie(name, b"opened");
        body = b"retry: 2\ndata: opened\n\n";

    return status, headers, body