From eedaf90c840f2b66e0cd537ccd462df19b3f5dcf Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 11 Nov 2020 14:22:40 +0000 Subject: [PATCH] Better error message when a remote resource uses invalid Content-Type (#8719) --- changelog.d/8719.misc | 1 + synapse/http/matrixfederationclient.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelog.d/8719.misc diff --git a/changelog.d/8719.misc b/changelog.d/8719.misc new file mode 100644 index 0000000000..9aabef8fc3 --- /dev/null +++ b/changelog.d/8719.misc @@ -0,0 +1 @@ +Improve the error message returned when a remote server incorrectly sets the `Content-Type` header in response to a JSON request. diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py index 04766ca965..7e17cdb73e 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py @@ -1063,13 +1063,19 @@ def check_content_type_is_json(headers): """ c_type = headers.getRawHeaders(b"Content-Type") if c_type is None: - raise RequestSendFailed(RuntimeError("No Content-Type header"), can_retry=False) + raise RequestSendFailed( + RuntimeError("No Content-Type header received from remote server"), + can_retry=False, + ) c_type = c_type[0].decode("ascii") # only the first header val, options = cgi.parse_header(c_type) if val != "application/json": raise RequestSendFailed( - RuntimeError("Content-Type not application/json: was '%s'" % c_type), + RuntimeError( + "Remote server sent Content-Type header of '%s', not 'application/json'" + % c_type, + ), can_retry=False, )