Skip to content

Commit

Permalink
Make it possible to disable the check that subdomains are accessible.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Jan 14, 2014
1 parent 718555c commit b57f396
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions config.default.json
Expand Up @@ -3,4 +3,5 @@
"https":["auto"],
"ws":["auto"]},
"external_domain":"w3c-test.org",
"check_subdomains": true,
"log_level":"debug"}
17 changes: 11 additions & 6 deletions serve.py
Expand Up @@ -92,17 +92,14 @@ def kill(self):
self.proc.terminate()
self.proc.join()

def probe_subdomains(config):
host = config["host"]
def check_subdomains(config, subdomains):
port = get_port()
wrapper = ServerProc()
wrapper.start(start_http_server, config, port)

rv = {}

for subdomain in subdomains:
#This assumes that the tld is ascii-only or already in punycode
punycode = subdomain.encode("idna")
for subdomain, (punycode, host) in subdomains.iteritems():
domain = "%s.%s" % (punycode, host)
try:
urllib2.urlopen("http://%s:%d/" % (domain, port))
Expand All @@ -121,6 +118,12 @@ def probe_subdomains(config):

return rv

def get_subdomains(config):
#This assumes that the tld is ascii-only or already in punycode
host = config["host"]
return {subdomain: (subdomain.encode("idna"), host)
for subdomain in subdomains}

def start_servers(config, ports):
servers = defaultdict(list)

Expand Down Expand Up @@ -235,7 +238,9 @@ def normalise_config(config, domains, ports):

def start(config):
ports = get_ports(config)
domains = probe_subdomains(config)
domains = get_subdomains(config)
if config["check_subdomains"]:
domains = check_subdomains(config, domains)

config_ = normalise_config(config, domains, ports)

Expand Down

0 comments on commit b57f396

Please sign in to comment.