Merge branch 'master' into timeheap
[ashd.git] / examples / python / dynhosts / dynhosts
CommitLineData
7f838309
FT
1#!/usr/bin/python
2
3import os, sys, signal
4from ashd import util
5
6children = {}
7root = sys.argv[1]
0c345c82
FT
8
9# Automatically reap all children that die for any reason.
7f838309
FT
10signal.signal(signal.SIGCHLD, signal.SIG_IGN)
11
12def serve(req):
13 if "Host" in req:
14 # Strip port specification
15 dname = req["Host"].split(':')[0]
16 dname = dname.lower()
17 path = os.path.join(root, dname)
18 if os.path.isdir(path):
19 if dname not in children:
20 children[dname] = util.pchild(["dirplex", path], autorespawn = True)
21 children[dname].passreq(req)
22 return
ca92a4e5 23 util.respond(req, "No such host is configured.\n", status = "404 Not Found", ctype = "text/plain")
7f838309
FT
24
25util.serveloop(serve)