Squid-style external redirector for polipo doesn't work
Question: I am trying to write a trivial squid-style redirector for polipo http proxy,
as specified [in the
documentation](http://www.pps.jussieu.fr/~jch/software/polipo/manual/External-
redirectors.html#External-redirectors).

Here is the code:

    
    
    #!/usr/bin/python
    
    # based on
    # http://gofedora.com/how-to-write-custom-redirector-rewritor-plugin-squid-python/
    
    import sys
    
    def modify_url(line):
        l = line.split(" ")
        old_url = l[0]
        new_url = "\n"
        if "experts-exchange" in old_url:
            new_url = "http://127.0.0.1/" + new_url
        return new_url
    
    while True:
        line = sys.stdin.readline().strip()
        new_url = modify_url(line)
        sys.stdout.write(new_url)
        sys.stdout.flush()
    

When running polipo with this redirector and trying to access
<http://www.experts-exchange.com/>, I get the following error:

    
    
    500 Couldn't test for forbidden URL: Redirector error
    

Actually, I get the same error when trying to access any URL, which makes me
think it's a problem with my redirector code.

The output in polipo's log doesn't provide more hints, all I see there is:

    
    
    Redirector returned incomplete reply.
    

What am I doing wrong?

Edit: I have fixed modify_url() to return a value, because it did not. I'm
still getting the same error.


Answer: That site (gofedora) mentions that you need to return either a blank line or
the modified url in modify_url to make it work. Also you'll see the error if
you run this manually. Your solution is to return new_url at the end of
modify_url.

Please note that you also need to chmod +x to permit your proxy to run the
script.

