Commit ff85f6fe authored by Alexandre's avatar Alexandre
Browse files

Reduce amount of arguments on Connection initialisation

Do not pass head, post and dot args to ConnectionDoT
and ConnectionDoH on initialisation.
post and head are stored per Request
dot is redefined in ConnectionDoT and ConnectionDoH
parent 9627f1f6
......@@ -270,13 +270,14 @@ class RequestDoH(Request):
class Connection:
def __init__(self, server, servername=None, connect=None, forceIPv4=False, forceIPv6=False,
dot=False, verbose=verbose, insecure=insecure, post=post, head=head):
dot=dot, verbose=verbose, insecure=insecure):
if dot and not is_valid_hostname(server):
error("DoT requires a host name or IP address, not \"%s\"" % server)
if not dot and not is_valid_url(url):
error("DoH requires a valid HTTPS URL, not \"%s\"" % server)
if forceIPv4 and forceIPv6:
raise CustomException("Force IPv4 *or* IPv6 but not both")
self.dot = dot
self.server = server
self.servername = servername
if self.servername is not None:
......@@ -318,10 +319,9 @@ class Connection:
class ConnectionDoT(Connection):
def __init__(self, server, servername=None, connect=None, forceIPv4=False, forceIPv6=False,
dot=False, verbose=verbose, insecure=insecure, post=post, head=head):
verbose=verbose, insecure=insecure):
Connection.__init__(self, server, servername=servername, connect=connect,
forceIPv4=forceIPv4, forceIPv6=forceIPv6, dot=dot,
verbose=verbose, insecure=insecure, post=post, head=head)
forceIPv4=forceIPv4, forceIPv6=forceIPv6, dot=True, verbose=verbose, insecure=insecure)
self.check_ip_address(self.server)
self.hasher = hashlib.sha256()
addrinfo = socket.getaddrinfo(server, 853, self.family)
......@@ -395,12 +395,10 @@ class ConnectionDoT(Connection):
class ConnectionDoH(Connection):
def __init__(self, server, servername=None, connect=None, forceIPv4=False, forceIPv6=False,
dot=False, verbose=verbose, insecure=insecure, post=post, head=head):
verbose=verbose, insecure=insecure):
Connection.__init__(self, server, servername=servername, connect=connect,
forceIPv4=forceIPv4, forceIPv6=forceIPv6, dot=dot,
verbose=verbose, insecure=insecure, post=post, head=head)
self.post = post
self.head = head
forceIPv4=forceIPv4, forceIPv6=forceIPv6, dot=False,
verbose=verbose, insecure=insecure)
self.url = server
self.connect = connect
......@@ -444,9 +442,9 @@ class ConnectionDoH(Connection):
self.reset_opt_default()
except AttributeError:
self.create_handle()
if self.post or request.post:
if request.post:
self.prepare_post(request)
elif self.head or request.head:
elif request.head:
self.prepare_head(request)
request.head = True
else:
......@@ -494,6 +492,8 @@ class ConnectionDoH(Connection):
def do_test(self, qname, qtype=rtype):
request = RequestDoH(qname, qtype, want_dnssec=dnssec, use_edns=edns)
request.head = head
request.post = post
request.to_wire()
self.send_and_receive(request)
request.check_response()
......@@ -778,13 +778,13 @@ try:
else:
extracheck = None
if dot:
conn = ConnectionDoT(url, dot=dot, servername=extracheck, connect=connectTo, verbose=verbose,
conn = ConnectionDoT(url, servername=extracheck, connect=connectTo, verbose=verbose,
forceIPv4=forceIPv4, forceIPv6=forceIPv6,
insecure=insecure, post=post, head=head)
insecure=insecure)
else:
conn = ConnectionDoH(url, dot=dot, servername=extracheck, connect=connectTo, verbose=verbose,
conn = ConnectionDoH(url, servername=extracheck, connect=connectTo, verbose=verbose,
forceIPv4=forceIPv4, forceIPv6=forceIPv6,
insecure=insecure, post=post, head=head)
insecure=insecure)
except TimeoutError:
error("timeout")
except ConnectionRefusedError:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment