Quick Redirect
July 18th, 2010 by webstersprodigyI was recently using this to have total control over a redirect response without having to muck around with real servers. I figure I may reuse this at some point as stupid as it is.
#!/bin/python
#python response.py | ncat -l 80
import sys
import time
REDIRECT_SITE= "http://webstersprodigy.net"
gm_time = time.gmtime()
content_response = (
"""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\r\n""" +
"""<html><head>\r\n""" +
"""<title>302 Found</title>\r\n""" +
"""</head><body>\r\n""" +
"""<h1>Found</h1>\r\n""" +
"""<p>The document has moved <a href=\"""" + REDIRECT_SITE +
"""\">here</a>.</p>\r\n""" +
"""</body></html>\r\n\r\n""")
http_response = (
"HTTP/1.1 302 Found\r\n" +
"Server: Apache\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n" +
"Date: " + time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) + "\r\n"
"Location: " + REDIRECT_SITE + "\r\n" +
"Keep-Alive: timeout=20, max=997\r\n" +
"Expires: " + time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(time.time()+ 60*60*24))+ "\r\n"
"Content-Length: " + str(len(content_response)) + "\r\n")