mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-12 04:52:26 +01:00
Better error message when a remote resource uses invalid Content-Type (#8719)
This commit is contained in:
parent
4c7587ef99
commit
eedaf90c84
2 changed files with 9 additions and 2 deletions
1
changelog.d/8719.misc
Normal file
1
changelog.d/8719.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Improve the error message returned when a remote server incorrectly sets the `Content-Type` header in response to a JSON request.
|
|
@ -1063,13 +1063,19 @@ def check_content_type_is_json(headers):
|
||||||
"""
|
"""
|
||||||
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 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
|
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 RequestSendFailed(
|
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,
|
can_retry=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue