mitmproxy/test/mitmproxy/tools/passive_close.py

24 lines
681 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):
2016-01-27 09:12:18 +00:00
2014-10-17 15:08:41 +00:00
def handle(self):
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(
"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
2015-05-30 00:03:28 +00:00
server = ThreadedTCPServer(('', 1520), service)
2014-10-17 15:08:41 +00:00
server.serve_forever()