Skip to content
Snippets Groups Projects
Commit d422570e authored by Erik Johnston's avatar Erik Johnston
Browse files

Use RequestSendFailed when fail to parse content type headers

parent 83c50bf7
No related branches found
No related tags found
No related merge requests found
...@@ -823,21 +823,21 @@ def check_content_type_is_json(headers): ...@@ -823,21 +823,21 @@ def check_content_type_is_json(headers):
headers (twisted.web.http_headers.Headers): headers to check headers (twisted.web.http_headers.Headers): headers to check
Raises: Raises:
RuntimeError if the RequestSendFailed: if the Content-Type header is missing or isn't JSON
""" """
c_type = headers.getRawHeaders(b"Content-Type") c_type = headers.getRawHeaders(b"Content-Type")
if c_type is None: if c_type is None:
raise RuntimeError( raise RequestSendFailed(RuntimeError(
"No Content-Type header" "No Content-Type header"
) ), can_retry=False)
c_type = c_type[0].decode('ascii') # only the first header c_type = c_type[0].decode('ascii') # only the first header
val, options = cgi.parse_header(c_type) val, options = cgi.parse_header(c_type)
if val != "application/json": if val != "application/json":
raise RuntimeError( raise RequestSendFailed(RuntimeError(
"Content-Type not application/json: was '%s'" % c_type "Content-Type not application/json: was '%s'" % c_type
) ), can_retry=False)
def encode_query_args(args): def encode_query_args(args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment