Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename bind_hostname to bind_address #9998

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"wss":["auto"]},
"check_subdomains": true,
"log_level":"debug",
"bind_hostname": true,
"bind_address": true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change anything so old config.json files still work? (These are only supported with wpt serve and not wpt run, AFAIK.)

"ssl": {"type": "pregenerated",
"encrypt_after_connect": false,
"openssl": {
Expand Down
55 changes: 29 additions & 26 deletions tools/serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,19 @@ def __init__(self):
self.daemon = None
self.stop = Event()

def start(self, init_func, host, port, paths, routes, bind_hostname, config,
def start(self, init_func, host, port, paths, routes, bind_address, config,
ssl_config, **kwargs):
self.proc = Process(target=self.create_daemon,
args=(init_func, host, port, paths, routes, bind_hostname,
args=(init_func, host, port, paths, routes, bind_address,
config, ssl_config),
kwargs=kwargs)
self.proc.daemon = True
self.proc.start()

def create_daemon(self, init_func, host, port, paths, routes, bind_hostname,
def create_daemon(self, init_func, host, port, paths, routes, bind_address,
config, ssl_config, **kwargs):
try:
self.daemon = init_func(host, port, paths, routes, bind_hostname, config,
self.daemon = init_func(host, port, paths, routes, bind_address, config,
ssl_config, **kwargs)
except socket.error:
print("Socket error on port %s" % port, file=sys.stderr)
Expand Down Expand Up @@ -432,12 +432,12 @@ def is_alive(self):
return self.proc.is_alive()


def check_subdomains(host, paths, bind_hostname, ssl_config, aliases):
def check_subdomains(host, paths, bind_address, ssl_config, aliases):
port = get_port()
subdomains = get_subdomains(host)

wrapper = ServerProc()
wrapper.start(start_http_server, host, port, paths, build_routes(aliases), bind_hostname,
wrapper.start(start_http_server, host, port, paths, build_routes(aliases), bind_address,
None, ssl_config)

connected = False
Expand Down Expand Up @@ -490,7 +490,7 @@ def make_hosts_file(config, host):
return "".join(rv)


def start_servers(host, ports, paths, routes, bind_hostname, config, ssl_config,
def start_servers(host, ports, paths, routes, bind_address, config, ssl_config,
**kwargs):
servers = defaultdict(list)
for scheme, ports in ports.iteritems():
Expand All @@ -505,36 +505,36 @@ def start_servers(host, ports, paths, routes, bind_hostname, config, ssl_config,
"wss":start_wss_server}[scheme]

server_proc = ServerProc()
server_proc.start(init_func, host, port, paths, routes, bind_hostname,
server_proc.start(init_func, host, port, paths, routes, bind_address,
config, ssl_config, **kwargs)
servers[scheme].append((port, server_proc))

return servers


def start_http_server(host, port, paths, routes, bind_hostname, config, ssl_config,
def start_http_server(host, port, paths, routes, bind_address, config, ssl_config,
**kwargs):
return wptserve.WebTestHttpd(host=host,
port=port,
doc_root=paths["doc_root"],
routes=routes,
rewrites=rewrites,
bind_hostname=bind_hostname,
bind_address=bind_address,
config=config,
use_ssl=False,
key_file=None,
certificate=None,
latency=kwargs.get("latency"))


def start_https_server(host, port, paths, routes, bind_hostname, config, ssl_config,
def start_https_server(host, port, paths, routes, bind_address, config, ssl_config,
**kwargs):
return wptserve.WebTestHttpd(host=host,
port=port,
doc_root=paths["doc_root"],
routes=routes,
rewrites=rewrites,
bind_hostname=bind_hostname,
bind_address=bind_address,
config=config,
use_ssl=True,
key_file=ssl_config["key_path"],
Expand All @@ -544,7 +544,7 @@ def start_https_server(host, port, paths, routes, bind_hostname, config, ssl_con


class WebSocketDaemon(object):
def __init__(self, host, port, doc_root, handlers_root, log_level, bind_hostname,
def __init__(self, host, port, doc_root, handlers_root, log_level, bind_address,
ssl_config):
self.host = host
cmd_args = ["-p", port,
Expand All @@ -569,7 +569,7 @@ def __init__(self, host, port, doc_root, handlers_root, log_level, bind_hostname
"--certificate", ssl_config["cert_path"],
"--tls-module", tls_module]

if (bind_hostname):
if (bind_address):
cmd_args = ["-H", host] + cmd_args
opts, args = pywebsocket._parse_args_and_config(cmd_args)
opts.cgi_directories = []
Expand Down Expand Up @@ -608,25 +608,25 @@ def stop(self):
self.server = None


def start_ws_server(host, port, paths, routes, bind_hostname, config, ssl_config,
def start_ws_server(host, port, paths, routes, bind_address, config, ssl_config,
**kwargs):
return WebSocketDaemon(host,
str(port),
repo_root,
paths["ws_doc_root"],
"debug",
bind_hostname,
bind_address,
ssl_config = None)


def start_wss_server(host, port, paths, routes, bind_hostname, config, ssl_config,
def start_wss_server(host, port, paths, routes, bind_address, config, ssl_config,
**kwargs):
return WebSocketDaemon(host,
str(port),
repo_root,
paths["ws_doc_root"],
"debug",
bind_hostname,
bind_address,
ssl_config)


Expand Down Expand Up @@ -662,16 +662,19 @@ def normalise_config(config, ports):

domains[""] = host

ports_ = {}
for scheme, ports_used in ports.iteritems():
ports_[scheme] = ports_used
if "bind_hostname" in config:
logger.warning("bind_hostname in config is deprecated; use bind_address instead")
bind_address = config["bind_hostname"]
else:
bind_address = config["bind_address"]

# make a (shallow) copy of the config and update that, so that the
# normalized config can be used in place of the original one.
config_ = config.copy()
config_["domains"] = domains
config_["not_domains"] = not_domains
config_["ports"] = ports_
config_["bind_address"] = bind_address
return config_


Expand All @@ -692,10 +695,10 @@ def start(config, ssl_environment, routes, **kwargs):
host = config.get("host_ip") or config["host"]
ports = get_ports(config, ssl_environment)
paths = get_paths(config)
bind_hostname = config["bind_hostname"]
bind_address = config["bind_address"]
ssl_config = get_ssl_config(config, ssl_environment)

servers = start_servers(host, ports, paths, routes, bind_hostname, config,
servers = start_servers(host, ports, paths, routes, bind_address, config,
ssl_config, **kwargs)

return servers
Expand Down Expand Up @@ -813,15 +816,15 @@ def run(**kwargs):
ports = get_ports(config, ssl_env)
config = normalise_config(config, ports)
host = config["host"]
bind_hostname = config["bind_hostname"]
bind_address = config["bind_address"]

if config["check_subdomains"]:
paths = get_paths(config)
ssl_config = get_ssl_config(config, ssl_env)
check_subdomains(host, paths, bind_hostname, ssl_config, config["aliases"])
check_subdomains(host, paths, bind_address, ssl_config, config["aliases"])

stash_address = None
if bind_hostname:
if bind_address:
stash_address = (host, get_port())

with stash.StashServer(stash_address, authkey=str(uuid.uuid4())):
Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/browsers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def env_options():
# https://github.com/w3c/web-platform-tests/pull/9480
return {"host_ip": "127.0.0.1",
"host": "web-platform.test",
"bind_hostname": False,
"bind_address": False,
"certificate_domain": "web-platform.test",
"supports_debugger": True}

Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/browsers/servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def env_extras(**kwargs):
def env_options():
return {"host": "web-platform.test",
"host_ip": "127.0.0.1",
"bind_hostname": False,
"bind_address": False,
"testharnessreport": "testharnessreport-servo.js",
"supports_debugger": True}

Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/browsers/webkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def env_extras(**kwargs):


def env_options():
return {"bind_hostname": "true"}
return {}


class WebKitBrowser(Browser):
Expand Down
4 changes: 2 additions & 2 deletions tools/wptrunner/wptrunner/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def load_config(self):
if "host" in self.options:
local_config["host"] = self.options["host"]

if "bind_hostname" in self.options:
local_config["bind_hostname"] = self.options["bind_hostname"]
if "bind_address" in self.options:
local_config["bind_address"] = self.options["bind_address"]

with open(default_config_path) as f:
default_config = json.load(f)
Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/tests/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ def test_server_start_config(product):
config = args[0][0]
if "host" in env_options:
assert config["host"] == env_options["host"]
assert isinstance(config["bind_hostname"], bool)
assert isinstance(config["bind_address"], bool)
18 changes: 9 additions & 9 deletions tools/wptserve/wptserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class WebTestServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
daemon_threads = True

def __init__(self, server_address, request_handler_cls,
router, rewriter, bind_hostname,
router, rewriter, bind_address,
config=None, use_ssl=False, key_file=None, certificate=None,
encrypt_after_connect=False, latency=None, **kwargs):
"""Server for HTTP(s) Requests
Expand Down Expand Up @@ -141,10 +141,10 @@ def __init__(self, server_address, request_handler_cls,
This enables the server to act as a
self-proxy.

:param bind_hostname True to bind the server to both the hostname and
port specified in the server_address parameter.
False to bind the server only to the port in the
server_address parameter, but not to the hostname.
:param bind_address True to bind the server to both the IP address and
port specified in the server_address parameter.
False to bind the server only to the port in the
server_address parameter, but not to the address.
:param latency: Delay in ms to wait before seving each response, or
callable that returns a delay in ms
"""
Expand All @@ -156,7 +156,7 @@ def __init__(self, server_address, request_handler_cls,

self.latency = latency

if bind_hostname:
if bind_address:
hostname_port = server_address
else:
hostname_port = ("",server_address[1])
Expand Down Expand Up @@ -343,7 +343,7 @@ class WebTestHttpd(object):
:param rewrites: List of rewrites with which to initialize the rewriter_cls
:param config: Dictionary holding environment configuration settings for
handlers to read, or None to use the default values.
:param bind_hostname: Boolean indicating whether to bind server to hostname.
:param bind_address: Boolean indicating whether to bind server to IP address.
:param latency: Delay in ms to wait before seving each response, or
callable that returns a delay in ms

Expand Down Expand Up @@ -381,7 +381,7 @@ def __init__(self, host="127.0.0.1", port=8000,
server_cls=None, handler_cls=WebTestRequestHandler,
use_ssl=False, key_file=None, certificate=None, encrypt_after_connect=False,
router_cls=Router, doc_root=os.curdir, routes=None,
rewriter_cls=RequestRewriter, bind_hostname=True, rewrites=None,
rewriter_cls=RequestRewriter, bind_address=True, rewrites=None,
latency=None, config=None):

if routes is None:
Expand Down Expand Up @@ -409,7 +409,7 @@ def __init__(self, host="127.0.0.1", port=8000,
self.router,
self.rewriter,
config=config,
bind_hostname=bind_hostname,
bind_address=bind_address,
use_ssl=use_ssl,
key_file=key_file,
certificate=certificate,
Expand Down