8 scheme, url = url[:p], url[p + 3]
11 host, url = url[:p], url[p + 1:]
17 return scheme, host, url
20 out.write("usage: htredir [-hp] TARGET METHOD URL REST\n")
23 opts, args = getopt.getopt(sys.argv[1:], "hp")
29 status = "301 Moved Permanently"
33 target, method, url, rest = args
34 scheme = os.getenv("REQ_X_ASH_PROTOCOL")
35 host = os.getenv("REQ_HOST")
37 if me[-len(rest):] == rest:
39 tscheme, thost, target = destructurl(target)
40 if tscheme: scheme = tscheme
41 if thost: host = thost
42 if len(target) > 0 and target[0] == "/":
47 target = me[:p + 1] + target
48 if len(target) > 0 and target[0] == "/":
51 target = "%s://%s/%s" % (scheme, host, target)
53 # Illegal, but the only option (the premises are illegal anyway)
57 sys.stdout.write("HTTP/1.1 %s\n" % status)
58 sys.stdout.write("Location: %s\n" % target)
59 sys.stdout.write("Content-Length: 0\n")
60 sys.stdout.write("\n")