Commit 227f7bbf authored by Alexandre's avatar Alexandre
Browse files

[DoH] Warning message and refactoring

Custom header definition via command line option is not yet
supported with --check.
parent 3116745e
......@@ -769,11 +769,10 @@ def run_check_default(connection):
print()
return ok
def run_check_mime(connection, accept="application/dns-message", content_type="application/dns-message"):
def run_check_mime(connection, header):
if dot:
return True
ok = True
header = [f"Accept: {accept}", f"Content-type: {content_type}"]
if verbose:
test_name = f'Test mime: {", ".join(h for h in header)}'
print(test_name)
......@@ -790,9 +789,7 @@ def run_check_mime(connection, accept="application/dns-message", content_type="a
request.check_response(debug)
if not print_result(connection, request, prefix=f"Test Header {', '.join(header)}"):
ok = False
default = "application/dns-message"
default_header = [f"Accept: {default}", f"Content-type: {default}"]
handle.setopt(pycurl.HTTPHEADER, default_header)
handle.setopt(pycurl.HTTPHEADER, doh_header_default)
if verbose:
print()
return ok
......@@ -846,8 +843,8 @@ def run_check_additionals(connection):
# The DoH server is right to reject these (Example: 'HTTP
# error 415: only Content-Type: application/dns-message is
# supported')
run_check_mime(connection, accept="text/html")
run_check_mime(connection, content_type="text/html")
run_check_mime(connection, header=["Accept: text/html", "Content-type: application/dns-message"])
run_check_mime(connection, header=["Accept: application/dns-message", "Content-type: text/html"])
return True
def run_check(connection):
......@@ -987,8 +984,8 @@ if not monitoring:
if len(doh_header) > 0 and dot:
usage("Header definition makes no sense with --dot")
sys.exit(1)
if len(doh_header) == 0 and not dot and not check:
doh_header = ["Accept: application/dns-message", "Content-type: application/dns-message"]
if len(doh_header) > 0 and check:
print("Custom header value ignored: header definition not yet implemented with --check")
if ifile is None and (len(args) != 2 and len(args) != 3):
usage("Wrong number of arguments")
sys.exit(1)
......
Markdown is supported
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