summaryrefslogtreecommitdiffstats
path: root/test/modules/tls/htdocs/b.mod-tls.test/resp-jitter.py
blob: f7b134999df9c867fa451992ba7bf3a05a763a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3
import random
import sys
import time
from datetime import timedelta

random.seed()
to_write = total_len = random.randint(1, 10*1024*1024)

sys.stdout.write("Content-Type: application/octet-stream\n")
sys.stdout.write(f"Content-Length: {total_len}\n")
sys.stdout.write("\n")
sys.stdout.flush()

while to_write > 0:
    len = random.randint(1, 1024*1024)
    len = min(len, to_write)
    sys.stdout.buffer.write(random.randbytes(len))
    to_write -= len
    delay = timedelta(seconds=random.uniform(0.0, 0.5))
    time.sleep(delay.total_seconds())
sys.stdout.flush()