Skip to content

Commit

Permalink
Fix web-platform-tests#2669: Add alternate_hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed Mar 24, 2018
1 parent d04a8fc commit 833a869
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions config.default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{"browser_host": "web-platform.test",
"alternate_hosts": ["not-web-platform.test"],
"doc_root": null,
"ws_doc_root": null,
"server_host": null,
Expand Down
28 changes: 15 additions & 13 deletions tools/serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,25 +648,27 @@ def get_ports(config, ssl_environment):
def normalise_config(config, ports):
if "host" in config:
logger.warning("host in config is deprecated; use browser_host instead")
host = config["host"]
hosts = [config["host"]]
else:
host = config["browser_host"]
hosts = [config["browser_host"]]

hosts.extend(config["alternate_hosts"])

domains = get_subdomains(host)
not_domains = get_not_subdomains(host)
domains = []
not_domains = []
for host in hosts:
domains.append(
{k: ".".join(v)
for k, v in get_subdomains(host).iteritems()})
not_domains.append(
{k: ".".join(v)
for k, v in get_not_subdomains(host).iteritems()})
domains[-1][""] = host

ports_ = {}
for scheme, ports_used in ports.iteritems():
ports_[scheme] = ports_used

for key, value in domains.iteritems():
domains[key] = ".".join(value)

for key, value in not_domains.iteritems():
not_domains[key] = ".".join(value)

domains[""] = host

if "bind_hostname" in config:
logger.warning("bind_hostname in config is deprecated; use bind_address instead")
bind_address = config["bind_hostname"]
Expand All @@ -681,7 +683,7 @@ def normalise_config(config, ports):
config_["ports"] = ports_
config_["bind_address"] = bind_address
if config.get("server_host", None) is None:
config_["server_host"] = host
config_["server_host"] = hosts[0]
return config_


Expand Down
12 changes: 9 additions & 3 deletions tools/wptserve/wptserve/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,16 @@ def config_replacement(match):
value = FirstWrapper(request.GET)
elif field == "domains":
if ('not_domains' in request.server.config and
tokens[1][1] in request.server.config['not_domains']):
value = request.server.config['not_domains']
tokens[1][1] in request.server.config['not_domains'][0]):
value = request.server.config['not_domains'][0]
else:
value = request.server.config['domains']
value = request.server.config['domains'][0]
elif field == "alt_domains":
if ('not_domains' in request.server.config and
tokens[2][1] in request.server.config['not_domains']):
value = request.server.config['not_domains'][1:]
else:
value = request.server.config['domains'][1:]
elif field == "host":
value = request.server.config["browser_host"]
elif field in request.server.config:
Expand Down

0 comments on commit 833a869

Please sign in to comment.