Commit 0bce0cf5 authored by Stephane Bortzmeyer's avatar Stephane Bortzmeyer
Browse files

[DoH] Test the content type of the answer. Closes #1

parent 861563f4
......@@ -261,19 +261,26 @@ def do_test(connection, qname, qtype=rtype):
rcode = connection.curl.getinfo(pycurl.RESPONSE_CODE)
ok = True
if rcode == 200:
if not head:
body = buffer.getvalue()
try:
size = len(body)
response = dns.message.from_wire(body)
except dns.message.TrailingJunk: # Not DNS.
response = "ERROR Not proper DNS data, trailing junk \"%s\"" % body
ok = False
except dns.name.BadLabelType: # Not DNS.
response = "ERROR Not proper DNS data (wrong path in the URL?) \"%s\"" % body[:100]
ok = False
ctype = connection.curl.getinfo(pycurl.CONTENT_TYPE)
if ctype != "application/dns-message":
response = "Content type of the response (\"%s\") invalid" % ctype
ok = False
else:
response = "HEAD successful"
if not head:
body = buffer.getvalue()
try:
size = len(body)
response = dns.message.from_wire(body)
except dns.message.TrailingJunk: # Not DNS. Should
# not happen for a content type
# application/dns-message but who knows?
response = "ERROR Not proper DNS data, trailing junk \"%s\"" % body
ok = False
except dns.name.BadLabelType: # Not DNS.
response = "ERROR Not proper DNS data (wrong path in the URL?) \"%s\"" % body[:100]
ok = False
else:
response = "HEAD successful"
else:
ok = False
body = buffer.getvalue()
......
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