Line | |
---|
1 | #!/usr/bin/env python3 |
---|
2 | # |
---|
3 | # Copyright (C) 2015 Blindspot Security LLC |
---|
4 | # by Timothy D. Morgan |
---|
5 | # twits: @ecbftw |
---|
6 | |
---|
7 | import sys |
---|
8 | import time |
---|
9 | import socketserver |
---|
10 | import http.server |
---|
11 | |
---|
12 | |
---|
13 | class EchoHandler(http.server.BaseHTTPRequestHandler): |
---|
14 | """ |
---|
15 | """ |
---|
16 | |
---|
17 | def do_GET(self): |
---|
18 | #resolution = time.clock_getres(time.CLOCK_MONOTONIC) |
---|
19 | received = int(time.monotonic()*1000000000) |
---|
20 | wait_time = 0 |
---|
21 | if 't=' in self.path: |
---|
22 | wait_time = int(self.path.split('t=', 1)[1], 10) |
---|
23 | |
---|
24 | self.send_response(200) |
---|
25 | self.send_header('Content-Type','text/plain; charset=UTF-8') |
---|
26 | self.end_headers() |
---|
27 | |
---|
28 | self.wfile.write(b'header\n') |
---|
29 | self.wfile.flush() |
---|
30 | |
---|
31 | # Use a busy-wait with monotonic clock. More accurate than time.sleep() |
---|
32 | finish = received + wait_time |
---|
33 | now = int(time.monotonic()*1000000000) |
---|
34 | while now < finish: |
---|
35 | now = int(time.monotonic()*1000000000) |
---|
36 | |
---|
37 | self.wfile.write(b'body\n') |
---|
38 | self.wfile.flush() |
---|
39 | |
---|
40 | self.wfile.write(b'more content\n') |
---|
41 | self.wfile.flush() |
---|
42 | |
---|
43 | self.wfile.write(b'footer\n') |
---|
44 | self.wfile.flush() |
---|
45 | |
---|
46 | |
---|
47 | if __name__ == "__main__": |
---|
48 | HOST, PORT = "0.0.0.0", 3240 |
---|
49 | server = socketserver.TCPServer((HOST, PORT), EchoHandler) |
---|
50 | server.serve_forever() |
---|
Note: See
TracBrowser
for help on using the repository browser.