diff --git a/config.default.json b/config.default.json index 7230aa4f047e8a..2a3dfcc0a4a268 100644 --- a/config.default.json +++ b/config.default.json @@ -3,4 +3,5 @@ "https":["auto"], "ws":["auto"]}, "external_domain":"w3c-test.org", + "check_subdomains": true, "log_level":"debug"} diff --git a/serve.py b/serve.py index f037f4f2c27cdc..54194fea5f7a81 100644 --- a/serve.py +++ b/serve.py @@ -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)) @@ -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) @@ -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)