您需要提供自己的 do _ GET ()实例(如果选择支持 HEAD 操作,还需要 do _ HEAD ()实例):
class MyHTTPServer(SimpleHTTPServer):
allowed_hosts = (('127.0.0.1', 80),)
def do_GET(self):
if self.client_address not in allowed_hosts:
self.send_response(401, 'request not allowed')
else:
super(MyHTTPServer, self).do_Get()