|
4 | 4 | import json
|
5 | 5 | from urllib.parse import urljoin
|
6 | 6 |
|
7 |
| -import httpx |
| 7 | +import niquests |
8 | 8 | import msgpack
|
9 | 9 |
|
10 | 10 | from ably.rest.auth import Auth
|
@@ -86,10 +86,10 @@ def version(self):
|
86 | 86 |
|
87 | 87 | class Response:
|
88 | 88 | """
|
89 |
| - Composition for httpx.Response with delegation |
| 89 | + Composition for niquests.Response with delegation |
90 | 90 | """
|
91 | 91 |
|
92 |
| - def __init__(self, response): |
| 92 | + def __init__(self, response: niquests.Response): |
93 | 93 | self.__response = response
|
94 | 94 |
|
95 | 95 | def to_native(self):
|
@@ -129,10 +129,10 @@ def __init__(self, ably, options):
|
129 | 129 | # Cached fallback host (RSC15f)
|
130 | 130 | self.__host = None
|
131 | 131 | self.__host_expires = None
|
132 |
| - self.__client = httpx.AsyncClient(http2=True) |
| 132 | + self.__client = niquests.AsyncSession() |
133 | 133 |
|
134 | 134 | async def close(self):
|
135 |
| - await self.__client.aclose() |
| 135 | + await self.__client.close() |
136 | 136 |
|
137 | 137 | def dump_body(self, body):
|
138 | 138 | if self.options.use_binary_protocol:
|
@@ -196,18 +196,24 @@ def should_stop_retrying():
|
196 | 196 | base_url = "%s://%s:%d" % (self.preferred_scheme,
|
197 | 197 | host,
|
198 | 198 | self.preferred_port)
|
| 199 | + |
| 200 | + # remove redundant port in base_url |
| 201 | + if self.preferred_scheme == "https" and self.preferred_port == 443: |
| 202 | + base_url = base_url.replace(":443", "") |
| 203 | + elif self.preferred_scheme == "http" and self.preferred_port == 80: |
| 204 | + base_url = base_url.replace(":80", "") |
| 205 | + |
199 | 206 | url = urljoin(base_url, path)
|
200 | 207 |
|
201 |
| - request = self.__client.build_request( |
202 |
| - method=method, |
203 |
| - url=url, |
204 |
| - content=body, |
205 |
| - params=params, |
206 |
| - headers=all_headers, |
207 |
| - timeout=timeout, |
208 |
| - ) |
209 | 208 | try:
|
210 |
| - response = await self.__client.send(request) |
| 209 | + response = await self.__client.request( |
| 210 | + method=method, |
| 211 | + url=url, |
| 212 | + data=body, |
| 213 | + params=params, |
| 214 | + headers=all_headers, |
| 215 | + timeout=timeout, |
| 216 | + ) |
211 | 217 | except Exception as e:
|
212 | 218 | if should_stop_retrying():
|
213 | 219 | raise e
|
|
0 commit comments