我正在运行safesquid,它确实支持外部parsing器,所以我写了这个简单的URL重写代码在Python中,也logging了最初的请求…
#!/usr/bin/env python import sys def modify_url(line): list = line.split(' ') old_url = list[0] new_url = '\n' if old_url.endswith('.avi'): new_url = 'http://www.yahoo.com' else: new_url = old_url return new_url def main(): while True: line = sys.stdin.readline().strip() log = open('/tmp/redirect.log', 'a') log.write(line + "\n") log.close() new_url = modify_url(line) sys.stdout.write(new_url) sys.stdout.flush() if __name__ == '__main__': main()
我在safesquid上得到这些错误
2012 01 30 17:19:45 [225] request: request for web interface from 192.168.221.1 2012 01 30 17:19:45 [225] external: parsed with /opt/safesquid/safesquid/scripts/redirect.py 2012 01 30 17:19:45 [225] external: error: external parser sent null or invalid request headers 2012 01 30 17:19:45 [225] error: security: malformatted header received 2012 01 30 17:19:45 [225] external: parsed with /opt/safesquid/safesquid/scripts/redirect.py 2012 01 30 17:19:45 [225] external: error: external parser sent null or invalid request headers
此外,最初的请求日志是空的,但是文件很大,我想它必须附加“\ n”的文件….
任何想法如何我可以捕获来自safesquid的请求?
如果您想重写或redirectURL,那么您可以简单地使用SafeSquid的URLredirect或重写文档function。