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