Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit eedaf90

Browse files
Better error message when a remote resource uses invalid Content-Type (#8719)
1 parent 4c7587e commit eedaf90

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

changelog.d/8719.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the error message returned when a remote server incorrectly sets the `Content-Type` header in response to a JSON request.

synapse/http/matrixfederationclient.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,13 +1063,19 @@ def check_content_type_is_json(headers):
10631063
"""
10641064
c_type = headers.getRawHeaders(b"Content-Type")
10651065
if c_type is None:
1066-
raise RequestSendFailed(RuntimeError("No Content-Type header"), can_retry=False)
1066+
raise RequestSendFailed(
1067+
RuntimeError("No Content-Type header received from remote server"),
1068+
can_retry=False,
1069+
)
10671070

10681071
c_type = c_type[0].decode("ascii") # only the first header
10691072
val, options = cgi.parse_header(c_type)
10701073
if val != "application/json":
10711074
raise RequestSendFailed(
1072-
RuntimeError("Content-Type not application/json: was '%s'" % c_type),
1075+
RuntimeError(
1076+
"Remote server sent Content-Type header of '%s', not 'application/json'"
1077+
% c_type,
1078+
),
10731079
can_retry=False,
10741080
)
10751081

0 commit comments

Comments
 (0)