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

Commit

Permalink
Better error message when a remote resource uses invalid Content-Type (
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Nov 11, 2020
1 parent 4c7587e commit eedaf90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/8719.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the error message returned when a remote server incorrectly sets the `Content-Type` header in response to a JSON request.
10 changes: 8 additions & 2 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down

0 comments on commit eedaf90

Please sign in to comment.