diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index e7b2c409a..0d1ad6924 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -423,7 +423,11 @@ class AppRegistry: """ Returns an WSGIAdaptor instance if request matches an app, or None. """ - return self.apps.get((request.host, request.port), None) + if (request.host, request.port) in self.apps: + return self.apps[(request.host, request.port)] + if "host" in request.headers: + host = request.headers["host"][0] + return self.apps.get((host, request.port), None) class DummyServer: diff --git a/test/test_proxy.py b/test/test_proxy.py index d4d275b5a..105871689 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -21,3 +21,11 @@ def test_app_registry(): r.port = 81 assert not ar.get(r) + + + r = tutils.treq() + r.host = "domain2" + r.port = 80 + assert not ar.get(r) + r.headers["host"] = ["domain"] + assert ar.get(r)