Squid url_rewrite_program is not working

PROXYrewritesquid

I'm writing a url_rewrite module for squid in python (OS: Ubuntu 13). For now the code is just a test which should print the received stdin to a file:

#!/usr/bin/python

import sys,os

url = sys.stdin.read()

os.system('echo "%s" >> log.txt' % url)
sys.stdout.write(url)
sys.stdout.flush()

When I start squid and launch a request from my browser connected to the proxy it doesn't work and checking the logs I can see some related errors:

syslog:

squid3: The redirector helpers are crashing too rapidly, need help!

cache.log

2013/09/30 14:51:44| WARNING: redirector #1 (FD 7) exited
2013/09/30 14:51:44| WARNING: redirector #2 (FD 9) exited
2013/09/30 14:51:44| WARNING: redirector #3 (FD 11) exited
2013/09/30 14:51:44| WARNING: redirector #4 (FD 13) exited
2013/09/30 14:51:44| Too few redirector processes are running
2013/09/30 14:51:44| storeDirWriteCleanLogs: Starting...
2013/09/30 14:51:44|   Finished.  Wrote 0 entries.
2013/09/30 14:51:44|   Took 0.00 seconds (  0.00 entries/sec).
FATAL: The redirector helpers are crashing too rapidly, need help!

Did anyone faced this issue and can figure out how to solve it?
Regards.

Best Answer

Looks like a very rough example. Anyway:

  1. You are reading and writing only one line. Squid requires that you will process as much lines as needed.
  2. Squid configuration file holds a good example on how to do this (squid.conf-documented).
  3. If you need some working example I already wrote one of those redirectors in python: http://code.google.com/p/squid-tagger/. Glad if it would help anyone besides me.