[tor-commits] [flashproxy/master] Add defhost and defport to read_client_registrations.
infinity0 at torproject.org
infinity0 at torproject.org
Mon Oct 28 14:47:41 UTC 2013
commit 13325d09e1201398a745ac4a03e12e2b597a97c0
Author: David Fifield <david at bamsoftware.com>
Date: Thu Oct 17 04:27:02 2013 -0700
Add defhost and defport to read_client_registrations.
Inspired by
"http registration: set default remote address properly - put_reg FROM is never actually read by facilitator"
https://github.com/infinity0/flashproxy/commit/4b8d3d65fbc78eca400e6c33e9987f923a7b18a1
---
facilitator/fac.py | 4 ++--
facilitator/facilitator-test | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/facilitator/fac.py b/facilitator/fac.py
index 8daa73c..a1ac614 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -161,11 +161,11 @@ def get_single(qs, key, default=None):
raise ValueError("more than one %r key" % key)
return vals[0]
-def read_client_registrations(body):
+def read_client_registrations(body, defhost=None, defport=None):
"""Parse the lines of body and yield an Endpoint for each."""
for line in body.splitlines():
qs = urlparse.parse_qs(line, keep_blank_values=True, strict_parsing=True)
- addr = parse_addr_spec(get_single(qs, "client"))
+ addr = parse_addr_spec(get_single(qs, "client"), defhost, defport)
transport = get_single(qs, "client-transport", DEFAULT_CLIENT_TRANSPORT)
yield Endpoint(addr, transport)
diff --git a/facilitator/facilitator-test b/facilitator/facilitator-test
index 35c2e2e..024972a 100755
--- a/facilitator/facilitator-test
+++ b/facilitator/facilitator-test
@@ -402,6 +402,12 @@ class ReadClientRegistrationsTest(unittest.TestCase):
self.assertEqual(len(l), 1)
self.assertEqual(l[0].addr, ("1::2", 3333))
+ def testDefaultAddress(self):
+ l = list(fac.read_client_registrations("client=:1111&transport=websocket", defhost="1.2.3.4"))
+ self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
+ l = list(fac.read_client_registrations("client=1.2.3.4:&transport=websocket", defport=1111))
+ self.assertEqual(l[0].addr, ("1.2.3.4", 1111))
+
def testDefaultTransport(self):
l = list(fac.read_client_registrations("client=1.2.3.4:1111"))
self.assertEqual(l[0].transport, "websocket")
More information about the tor-commits
mailing list