Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 02 Dec 2016 19:44:28 +0000
changeset 325361 d237751e0dea92a3b033a7b44855238c12c9ce86
parent 325360 d4657cdb08125a7daab950a72066df1332f25f21
child 325362 dc7d74a8a4bad3ca3beca17491775bd3e19b829d
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo Allows HTTPDs to be started on a custom networking interface (host) by using the `host` keyword argument. This may be passed to `serve.http_server`, `serve.https_server`, `serve.start_servers`, and `serve.start`. This also changes the default host to, which is a loopback device. MozReview-Commit-ID: 3QeMx3zqPyW
--- a/testing/marionette/harness/marionette/runner/serve.py
+++ b/testing/marionette/harness/marionette/runner/serve.py
@@ -10,18 +10,16 @@ processes.
 import argparse
 import multiprocessing
 import os
 import sys
 from collections import defaultdict
-import moznetwork
 import httpd
 __all__ = ["default_doc_root",
@@ -132,25 +130,26 @@ class ServerProc(BlockingChannel):
     def is_alive(self):
         if self.proc is not None:
             return self.proc.is_alive()
         return False
-def http_server(doc_root, ssl_config, **kwargs):
-    return httpd.FixtureServer(doc_root, url="http://%s:0/" % moznetwork.get_ip())
+def http_server(doc_root, ssl_config, host="", **kwargs):
+    return httpd.FixtureServer(doc_root, url="http://{}:0/".format(host), **kwargs)
-def https_server(doc_root, ssl_config, **kwargs):
+def https_server(doc_root, ssl_config, host="", **kwargs):
     return httpd.FixtureServer(doc_root,
-                               url="https://%s:0/" % moznetwork.get_ip(),
+                               url="https://{}:0/".format(host),
-                               ssl_cert=ssl_config["cert_path"])
+                               ssl_cert=ssl_config["cert_path"],
+                               **kwargs)
 def start_servers(doc_root, ssl_config, **kwargs):
     servers = defaultdict()
     for schema, builder_fn in registered_servers:
         proc = ServerProc(builder_fn)
         proc.start(doc_root, ssl_config, **kwargs)
         servers[schema] = (proc.get_url("/"), proc)
@@ -168,17 +167,16 @@ def start(doc_root=None, **kwargs):
     doc_root = doc_root or default_doc_root
     ssl_config = {"cert_path": httpd.default_ssl_cert,
                   "key_path": httpd.default_ssl_key}
     global servers
     servers = start_servers(doc_root, ssl_config, **kwargs)
     return servers
 def where_is(uri, on="http"):
     """Returns the full URL, including scheme, hostname, and port, for
     a fixture resource from the server associated with the ``on`` key.
     It will by default look for the resource in the "http" server.
@@ -207,17 +205,17 @@ def main(args):
     parser = argparse.ArgumentParser()
     parser.add_argument("-r", dest="doc_root",
                         help="Path to document root.  Overrides default.")
     args = parser.parse_args()
     servers = start(args.doc_root)
     for url in iter_url(servers):
-        print >>sys.stderr, "%s: listening on %s" % (sys.argv[0], url)
+        print >>sys.stderr, "{}: listening on {}".format(sys.argv[0], url)
         while any(proc.is_alive for proc in iter_proc(servers)):
             for proc in iter_proc(servers):
     except KeyboardInterrupt:
         for proc in iter_proc(servers):