Last active
January 10, 2017 11:07
-
-
Save edmondburnett/e5d0a487e4a898931548 to your computer and use it in GitHub Desktop.
squid custom rewriter script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import re | |
port_regex = re.compile(r':8082') | |
def rewrite_url(line): | |
""" If the input URL contains a port number, strip it out """ | |
url_list = line.split(' ') | |
old_url = url_list[0] | |
new_url = '\n' | |
if port_regex.search(old_url): | |
new_url = re.sub(port_regex, '', old_url, count=1) + new_url | |
return new_url | |
while True: | |
line = sys.stdin.readline().strip() | |
new_url = rewrite_url(line) | |
sys.stdout.write(new_url) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment