| 188 | |
| 189 | |
| 190 | async def _fetch(url: str = None, method: str = 'GET', json: str = None, data = None) -> Any: |
| 191 | logger.debug(f'_fetch( url="${url}" , method="${method}", data="${data}"') |
| 192 | global http_session |
| 193 | if method == 'GET': |
| 194 | async with http_session.get(url) as response: |
| 195 | content = await response.read() |
| 196 | return response, content |
| 197 | elif method == 'PUT': |
| 198 | async with http_session.put(url) as response: |
| 199 | content = await response.read() |
| 200 | return response, content |
| 201 | elif method == 'POST': |
| 202 | async with http_session.post(url, json=json, data=data ) as response: |
| 203 | content = await response.read() |
| 204 | return response, content |
| 205 | else: |
| 206 | raise NotImplementedError( |
| 207 | f'HTTP method ${method} not implemented.' |
| 208 | ' Contributions welcome!') |
| 209 | |
| 210 | |
| 211 | async def _pong(peer_connection=None): |