mitmproxy/test/helper_tools/passive_close.py

25 lines
694 B
Python
Raw Normal View History

2016-10-17 03:38:31 +00:00
import socketserver
2014-10-17 15:08:41 +00:00
from time import sleep
2015-05-30 00:03:28 +00:00
2016-03-20 21:50:03 +00:00
class service(socketserver.BaseRequestHandler):
2014-10-17 15:08:41 +00:00
def handle(self):
2022-04-26 11:53:35 +00:00
data = "dummy"
2016-04-14 05:34:28 +00:00
print("Client connected with ", self.client_address)
2014-10-17 15:08:41 +00:00
while True:
2015-05-30 00:03:28 +00:00
self.request.send(
2022-04-26 11:53:35 +00:00
"HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 7\r\n\r\ncontent"
)
2014-10-17 15:08:41 +00:00
data = self.request.recv(1024)
if not len(data):
2016-04-14 05:34:28 +00:00
print("Connection closed by remote: ", self.client_address)
2014-10-17 15:08:41 +00:00
sleep(3600)
2016-03-20 21:50:03 +00:00
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
2014-10-17 15:08:41 +00:00
pass
2016-11-16 21:39:15 +00:00
2022-04-26 11:53:35 +00:00
server = ThreadedTCPServer(("", 1520), service)
2014-10-17 15:08:41 +00:00
server.serve_forever()