summaryrefslogtreecommitdiffstats
path: root/tests/servers/large_response.py
blob: fd85b627104a705ffb6d62418c555155c1acb5b1 (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
36
"""This server returns a particuarly large response."""
import asyncio
import threading
import sys
from concurrent.futures import ThreadPoolExecutor

from pygls.server import aio_readline


def handler(data):
    payload = dict(
        jsonrpc="2.0",
        id=1,
        result=dict(
            numbers=list(range(100_000)),
        ),
    )
    content = str(payload).replace("'", '"')
    message = f"Content-Length: {len(content)}\r\n\r\n{content}".encode("utf8")

    sys.stdout.buffer.write(message)
    sys.stdout.flush()


async def main():
    await aio_readline(
        asyncio.get_running_loop(),
        ThreadPoolExecutor(),
        threading.Event(),
        sys.stdin.buffer,
        handler,
    )


if __name__ == "__main__":
    asyncio.run(main())