Skip to content

Instantly share code, notes, and snippets.

@edmondburnett
Last active January 10, 2017 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save edmondburnett/e5d0a487e4a898931548 to your computer and use it in GitHub Desktop.
Save edmondburnett/e5d0a487e4a898931548 to your computer and use it in GitHub Desktop.
squid custom rewriter script
#!/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