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 *
12 async def request(self
, *, url
: str, method
: str, data
=None) -> Tuple
[int, Any
]:
15 if method
not in {"POST", "PUT"}:
19 headers
= {"Content-Type": "application/json"}
20 body
= json
.dumps(data
) if data
is not None else None
21 full_url
= self
.prefix
+ url
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
29 response_body
= await response
.read()
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": ""}
38 url
=strip_auth(full_url
),
44 return response
.status
, data
47 Connection
.request
= request