httpapi: let httpapi plugin handle HTTPErrors other than 401 (#43436)

* Hold httpapi response in BytesIO

* Let httpapi plugin deal with HTTP codes if it wants

* Python 3.5 won't json.loads() bytes

* Don't modify headers passed to send

* Move code handling back to send()

but let httpapi plugin have a say on how it happens
This commit is contained in:
Nathaniel Case 2018-08-13 10:25:06 -04:00 committed by GitHub
parent 65772ede26
commit a3385a60b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 23 deletions

View file

@ -30,13 +30,16 @@ class HttpApi(HttpApiBase):
request = request_builder(data, output)
headers = {'Content-Type': 'application/json-rpc'}
response, response_text = self.connection.send('/command-api', request, headers=headers, method='POST')
try:
response_text = json.loads(response_text)
except ValueError:
raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text))
response, response_data = self.connection.send('/command-api', request, headers=headers, method='POST')
results = handle_response(response_text)
try:
response_data = json.loads(to_text(response_data.getvalue()))
except ValueError:
raise ConnectionError('Response was not valid JSON, got {0}'.format(
to_text(response_data.getvalue())
))
results = handle_response(response_data)
if self._become:
results = results[1:]