Commit 727b35a9 authored by Alexandre's avatar Alexandre
Browse files

[DoH] Store HTTP method in Request object (POST,HEAD)

parent 7c62af21
......@@ -190,6 +190,7 @@ class RequestDoH:
self.message.id = 0 # DoH requests that
self.message.flags |= dns.flags.AD # Ask for validation
self.data = self.message.to_wire()
self.post = False
self.head = False
def check_response(self):
......@@ -199,7 +200,7 @@ class RequestDoH:
self.response = "Content type of the response (\"%s\") invalid" % self.ctype
ok = False
else:
if not head:
if not self.head:
try:
self.response = dns.message.from_wire(self.body)
except dns.message.TrailingJunk: # Not DNS. Should
......@@ -227,7 +228,7 @@ class RequestDoH:
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=False, 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):
......@@ -305,10 +306,10 @@ 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):
dot=False, 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)
verbose=verbose, insecure=insecure)
self.check_ip_address(self.server)
self.hasher = hashlib.sha256()
addrinfo = socket.getaddrinfo(server, 853, self.family)
......@@ -377,12 +378,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):
dot=False, 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
verbose=verbose, insecure=insecure)
self.url = server
self.connect = connect
......@@ -426,11 +425,10 @@ class ConnectionDoH(Connection):
self.reset_opt_default()
except AttributeError:
self.create_handle()
if self.post:
if request.post:
self.prepare_post(request)
elif self.head:
elif request.head:
self.prepare_head(request)
request.head = True
else:
self.prepare_get(request)
......@@ -440,11 +438,13 @@ class ConnectionDoH(Connection):
self.set_opt(pycurl.URL, self.server + ("?dns=%s" % dns_req))
def prepare_post(self, request):
request.post = True
self.set_opt(pycurl.POST, True)
self.set_opt(pycurl.POSTFIELDS, request.data)
self.set_opt(pycurl.URL, self.server)
def prepare_head(self, request):
request.head = True
self.prepare_get(request)
self.set_opt(pycurl.NOBODY, True)
......@@ -471,6 +471,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
self.send_and_receive(request)
request.check_response()
return (request.rcode, request.response, request.body_size)
......@@ -628,11 +630,11 @@ try:
if dot:
conn = ConnectionDoT(url, dot=dot, 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,
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