Skip to content
Snippets Groups Projects
Unverified Commit a53e0160 authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

Ensure the msg property of HttpResponseException is a string. (#7979)

parent d90087cf
No related branches found
No related tags found
No related merge requests found
Switch to the JSON implementation from the standard library and bump the minimum version of the canonicaljson library to 1.2.0.
...@@ -395,7 +395,9 @@ class SimpleHttpClient(object): ...@@ -395,7 +395,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300: if 200 <= response.code < 300:
return json.loads(body.decode("utf-8")) return json.loads(body.decode("utf-8"))
else: else:
raise HttpResponseException(response.code, response.phrase, body) raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks @defer.inlineCallbacks
def post_json_get_json(self, uri, post_json, headers=None): def post_json_get_json(self, uri, post_json, headers=None):
...@@ -436,7 +438,9 @@ class SimpleHttpClient(object): ...@@ -436,7 +438,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300: if 200 <= response.code < 300:
return json.loads(body.decode("utf-8")) return json.loads(body.decode("utf-8"))
else: else:
raise HttpResponseException(response.code, response.phrase, body) raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_json(self, uri, args={}, headers=None): def get_json(self, uri, args={}, headers=None):
...@@ -509,7 +513,9 @@ class SimpleHttpClient(object): ...@@ -509,7 +513,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300: if 200 <= response.code < 300:
return json.loads(body.decode("utf-8")) return json.loads(body.decode("utf-8"))
else: else:
raise HttpResponseException(response.code, response.phrase, body) raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_raw(self, uri, args={}, headers=None): def get_raw(self, uri, args={}, headers=None):
...@@ -544,7 +550,9 @@ class SimpleHttpClient(object): ...@@ -544,7 +550,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300: if 200 <= response.code < 300:
return body return body
else: else:
raise HttpResponseException(response.code, response.phrase, body) raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
# XXX: FIXME: This is horribly copy-pasted from matrixfederationclient. # XXX: FIXME: This is horribly copy-pasted from matrixfederationclient.
# The two should be factored out. # The two should be factored out.
......
...@@ -447,6 +447,7 @@ class MatrixFederationHttpClient(object): ...@@ -447,6 +447,7 @@ class MatrixFederationHttpClient(object):
).inc() ).inc()
set_tag(tags.HTTP_STATUS_CODE, response.code) set_tag(tags.HTTP_STATUS_CODE, response.code)
response_phrase = response.phrase.decode("ascii", errors="replace")
if 200 <= response.code < 300: if 200 <= response.code < 300:
logger.debug( logger.debug(
...@@ -454,7 +455,7 @@ class MatrixFederationHttpClient(object): ...@@ -454,7 +455,7 @@ class MatrixFederationHttpClient(object):
request.txn_id, request.txn_id,
request.destination, request.destination,
response.code, response.code,
response.phrase.decode("ascii", errors="replace"), response_phrase,
) )
pass pass
else: else:
...@@ -463,7 +464,7 @@ class MatrixFederationHttpClient(object): ...@@ -463,7 +464,7 @@ class MatrixFederationHttpClient(object):
request.txn_id, request.txn_id,
request.destination, request.destination,
response.code, response.code,
response.phrase.decode("ascii", errors="replace"), response_phrase,
) )
# :'( # :'(
# Update transactions table? # Update transactions table?
...@@ -487,7 +488,7 @@ class MatrixFederationHttpClient(object): ...@@ -487,7 +488,7 @@ class MatrixFederationHttpClient(object):
) )
body = None body = None
e = HttpResponseException(response.code, response.phrase, body) e = HttpResponseException(response.code, response_phrase, body)
# Retry if the error is a 429 (Too Many Requests), # Retry if the error is a 429 (Too Many Requests),
# otherwise just raise a standard HttpResponseException # otherwise just raise a standard HttpResponseException
......
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