I'm trying to find a way, to shut down a Python webserver after a certain number of accesses/downloads. I simply run a Python webserver with the following code:
import http.server, socketserver
port = 8800
handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", port), handler)
httpd.serve_forever()
I want to stop serving, after a certain number of downloads/file-accesses have been reached.
A single file access is usually logged as:
192.168.0.1- - [01/Jan/1970 00:00:00] "GET /file.txt HTTP/1.1" 200 -
Is there a way to directly parse the logs of the webserver and react accordingly?
For instance, if a certain number of occurrences of "GET .* 200 -have been reached, stop serving.
http.server.SimpleHTTPRequestHandlerand make the derived class do whatever you want with the requests.