Backed out 4 changesets (bug 1825722) for causing reftest failures CLOSED TREE
[gecko.git] / testing / condprofile / condprof / patch.py
blob35e4c978b5fbe7d0c05ac67627d042e01abf45a9
1 # flake8: noqa
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 # patch for https://bugzilla.mozilla.org/show_bug.cgi?id=1655869
7 # see https://github.com/HDE/arsenic/issues/85
8 from arsenic.connection import *
11 @ensure_task
12 async def request(self, *, url: str, method: str, data=None) -> Tuple[int, Any]:
13 if data is None:
14 data = {}
15 if method not in {"POST", "PUT"}:
16 data = None
17 headers = {}
18 else:
19 headers = {"Content-Type": "application/json"}
20 body = json.dumps(data) if data is not None else None
21 full_url = self.prefix + url
22 log.info(
23 "request", url=strip_auth(full_url), method=method, body=body, headers=headers
26 async with self.session.request(
27 url=full_url, method=method, data=body, headers=headers
28 ) as response:
29 response_body = await response.read()
30 try:
31 data = json.loads(response_body)
32 except JSONDecodeError as exc:
33 log.error("json-decode", body=response_body)
34 data = {"error": "!internal", "message": str(exc), "stacktrace": ""}
35 wrap_screen(data)
36 log.info(
37 "response",
38 url=strip_auth(full_url),
39 method=method,
40 body=body,
41 response=response,
42 data=data,
44 return response.status, data
47 Connection.request = request