Skip to content
Myr

client.py

This file

Path

httpcore/client.py

682 lines · 19.1 KiB · Python

Last changed by

Auth (#65)Tom Christiebefore adoption5afa7dd

History of this file

Take it

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 1why, one step back
1import asyncio

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 2–4why, one step back
2import typing
3from types import TracebackType4

Auth (#65)Tom Christiebefore adoption5afa7dd

line 5why, one step back
5from .auth import HTTPBasicAuth

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 6–15why, one step back
6from .config import (
7 DEFAULT_MAX_REDIRECTS,8 DEFAULT_POOL_LIMITS,9 DEFAULT_SSL_CONFIG,10 DEFAULT_TIMEOUT_CONFIG,11 PoolLimits,12 SSLConfig,13 TimeoutConfig,14)15from .dispatch.connection_pool import ConnectionPool

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 16why, one step back
16from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

line 17why, one step back
17from .interfaces import ConcurrencyBackend, Dispatcher

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 18–19why, one step back
18from .models import (
19 URL,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 20why, one step back
20 AuthTypes,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 21why, one step back
21 Headers,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 22–24why, one step back
22 HeaderTypes,
23 QueryParamTypes,24 Request,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 25why, one step back
25 RequestData,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 26why, one step back
26 Response,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 27why, one step back
27 SyncResponse,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 28–29why, one step back
28 URLTypes,
29)

Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369

line 30why, one step back
30from .status_codes import codes

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 31–32why, one step back
31
32

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 33why, one step back
33class AsyncClient:

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 34–35why, one step back
34 def __init__(
35 self,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 36why, one step back
36 auth: AuthTypes = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 37–38why, one step back
37 ssl: SSLConfig = DEFAULT_SSL_CONFIG,
38 timeout: TimeoutConfig = DEFAULT_TIMEOUT_CONFIG,

Truckin' onTom Christiebefore adoption6b60d95

line 39why, one step back
39 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 40why, one step back
40 max_redirects: int = DEFAULT_MAX_REDIRECTS,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 41why, one step back
41 dispatch: Dispatcher = None,

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

line 42why, one step back
42 backend: ConcurrencyBackend = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 43why, one step back
43 ):

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 44why, one step back
44 if dispatch is None:

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

lines 45–47why, one step back
45 dispatch = ConnectionPool(
46 ssl=ssl, timeout=timeout, pool_limits=pool_limits, backend=backend47 )

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 48why, one step back
48

Auth (#65)Tom Christiebefore adoption5afa7dd

line 49why, one step back
49 self.auth = auth

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 50–51why, one step back
50 self.max_redirects = max_redirects
51 self.dispatch = dispatch

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 52–54why, one step back
52
53 async def get(54 self,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 55why, one step back
55 url: URLTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 56why, one step back
56 *,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 57why, one step back
57 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 58why, one step back
58 headers: HeaderTypes = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 59why, one step back
59 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 60why, one step back
60 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 61–63why, one step back
61 allow_redirects: bool = True,
62 ssl: SSLConfig = None,63 timeout: TimeoutConfig = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 64–65why, one step back
64 ) -> Response:
65 return await self.request(

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 66–67why, one step back
66 "GET",
67 url,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 68why, one step back
68 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 69–70why, one step back
69 headers=headers,
70 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 71why, one step back
71 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 72–74why, one step back
72 allow_redirects=allow_redirects,
73 ssl=ssl,74 timeout=timeout,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 75–76why, one step back
75 )
76

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 77–80why, one step back
77 async def options(
78 self,79 url: URLTypes,80 *,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 81why, one step back
81 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 82–83why, one step back
82 headers: HeaderTypes = None,
83 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 84why, one step back
84 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 85–91why, one step back
85 allow_redirects: bool = True,
86 ssl: SSLConfig = None,87 timeout: TimeoutConfig = None,88 ) -> Response:89 return await self.request(90 "OPTIONS",91 url,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 92why, one step back
92 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 93–94why, one step back
93 headers=headers,
94 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 95why, one step back
95 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 96–104why, one step back
96 allow_redirects=allow_redirects,
97 ssl=ssl,98 timeout=timeout,99 )100101 async def head(102 self,103 url: URLTypes,104 *,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 105why, one step back
105 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 106–107why, one step back
106 headers: HeaderTypes = None,
107 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 108why, one step back
108 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 109–115why, one step back
109 allow_redirects: bool = False, #  Note: Differs to usual default.
110 ssl: SSLConfig = None,111 timeout: TimeoutConfig = None,112 ) -> Response:113 return await self.request(114 "HEAD",115 url,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 116why, one step back
116 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 117–118why, one step back
117 headers=headers,
118 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 119why, one step back
119 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 120–124why, one step back
120 allow_redirects=allow_redirects,
121 ssl=ssl,122 timeout=timeout,123 )124

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 125–126why, one step back
125 async def post(
126 self,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 127why, one step back
127 url: URLTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 128why, one step back
128 *,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 129why, one step back
129 data: RequestData = b"",

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 130why, one step back
130 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 131why, one step back
131 headers: HeaderTypes = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 132why, one step back
132 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 133why, one step back
133 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 134–136why, one step back
134 allow_redirects: bool = True,
135 ssl: SSLConfig = None,136 timeout: TimeoutConfig = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 137–140why, one step back
137 ) -> Response:
138 return await self.request(139 "POST",140 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 141why, one step back
141 data=data,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 142why, one step back
142 query_params=query_params,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 143–144why, one step back
143 headers=headers,
144 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 145why, one step back
145 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 146why, one step back
146 allow_redirects=allow_redirects,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 147–150why, one step back
147 ssl=ssl,
148 timeout=timeout,149 )150

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 151–154why, one step back
151 async def put(
152 self,153 url: URLTypes,154 *,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 155why, one step back
155 data: RequestData = b"",

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 156why, one step back
156 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 157–158why, one step back
157 headers: HeaderTypes = None,
158 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 159why, one step back
159 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 160–166why, one step back
160 allow_redirects: bool = True,
161 ssl: SSLConfig = None,162 timeout: TimeoutConfig = None,163 ) -> Response:164 return await self.request(165 "PUT",166 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 167why, one step back
167 data=data,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 168why, one step back
168 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 169–170why, one step back
169 headers=headers,
170 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 171why, one step back
171 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 172–180why, one step back
172 allow_redirects=allow_redirects,
173 ssl=ssl,174 timeout=timeout,175 )176177 async def patch(178 self,179 url: URLTypes,180 *,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 181why, one step back
181 data: RequestData = b"",

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 182why, one step back
182 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 183–184why, one step back
183 headers: HeaderTypes = None,
184 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 185why, one step back
185 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 186–192why, one step back
186 allow_redirects: bool = True,
187 ssl: SSLConfig = None,188 timeout: TimeoutConfig = None,189 ) -> Response:190 return await self.request(191 "PATCH",192 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 193why, one step back
193 data=data,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 194why, one step back
194 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 195–196why, one step back
195 headers=headers,
196 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 197why, one step back
197 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 198–206why, one step back
198 allow_redirects=allow_redirects,
199 ssl=ssl,200 timeout=timeout,201 )202203 async def delete(204 self,205 url: URLTypes,206 *,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 207why, one step back
207 data: RequestData = b"",

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 208why, one step back
208 query_params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 209–210why, one step back
209 headers: HeaderTypes = None,
210 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 211why, one step back
211 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 212–218why, one step back
212 allow_redirects: bool = True,
213 ssl: SSLConfig = None,214 timeout: TimeoutConfig = None,215 ) -> Response:216 return await self.request(217 "DELETE",218 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 219why, one step back
219 data=data,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 220why, one step back
220 query_params=query_params,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 221–222why, one step back
221 headers=headers,
222 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 223why, one step back
223 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 224–228why, one step back
224 allow_redirects=allow_redirects,
225 ssl=ssl,226 timeout=timeout,227 )228

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 229–237why, one step back
229 async def request(
230 self,231 method: str,232 url: URLTypes,233 *,234 data: RequestData = b"",235 query_params: QueryParamTypes = None,236 headers: HeaderTypes = None,237 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 238why, one step back
238 auth: AuthTypes = None,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 239–249why, one step back
239 allow_redirects: bool = True,
240 ssl: SSLConfig = None,241 timeout: TimeoutConfig = None,242 ) -> Response:243 request = Request(244 method, url, data=data, query_params=query_params, headers=headers245 )246 self.prepare_request(request)247 response = await self.send(248 request,249 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 250why, one step back
250 auth=auth,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 251–256why, one step back
251 allow_redirects=allow_redirects,
252 ssl=ssl,253 timeout=timeout,254 )255 return response256

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 257why, one step back
257 def prepare_request(self, request: Request) -> None:

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 258why, one step back
258 request.prepare()

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 259–264why, one step back
259
260 async def send(261 self,262 request: Request,263 *,264 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 265why, one step back
265 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 266–267why, one step back
266 ssl: SSLConfig = None,
267 timeout: TimeoutConfig = None,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 268why, one step back
268 allow_redirects: bool = True,

Auth (#65)Tom Christiebefore adoption5afa7dd

lines 269–298why, one step back
269 ) -> Response:
270 if auth is None:271 auth = self.auth272273 url = request.url274 if auth is None and (url.username or url.password):275 auth = HTTPBasicAuth(username=url.username, password=url.password)276277 if auth is not None:278 if isinstance(auth, tuple):279 auth = HTTPBasicAuth(username=auth[0], password=auth[1])280 request = auth(request)281282 response = await self.send_handling_redirects(283 request,284 stream=stream,285 ssl=ssl,286 timeout=timeout,287 allow_redirects=allow_redirects,288 )289 return response290291 async def send_handling_redirects(292 self,293 request: Request,294 *,295 stream: bool = False,296 ssl: SSLConfig = None,297 timeout: TimeoutConfig = None,298 allow_redirects: bool = True,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 299why, one step back
299 history: typing.List[Response] = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 300why, one step back
300 ) -> Response:

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 301–302why, one step back
301 if history is None:
302 history = []

Finessing interfaceTom Christiebefore adoptiond7619a9

line 303why, one step back
303

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 304–310why, one step back
304 while True:
305 # We perform these checks here, so that calls to `response.next()`306 # will raise redirect errors if appropriate.307 if len(history) > self.max_redirects:308 raise TooManyRedirects()309 if request.url in [response.url for response in history]:310 raise RedirectLoop()

Finessing interfaceTom Christiebefore adoptiond7619a9

line 311why, one step back
311

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 312–318why, one step back
312 response = await self.dispatch.send(
313 request, stream=stream, ssl=ssl, timeout=timeout314 )315 response.history = list(history)316 history = [response] + history317 if not response.is_redirect:318 break

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 319why, one step back
319

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 320–326why, one step back
320 if allow_redirects:
321 request = self.build_redirect_request(request, response)322 else:323324 async def send_next() -> Response:325 nonlocal request, response, ssl, allow_redirects, timeout, history326 request = self.build_redirect_request(request, response)

Auth (#65)Tom Christiebefore adoption5afa7dd

line 327why, one step back
327 response = await self.send_handling_redirects(

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 328–356why, one step back
328 request,
329 stream=stream,330 allow_redirects=allow_redirects,331 ssl=ssl,332 timeout=timeout,333 history=history,334 )335 return response336337 response.next = send_next # type: ignore338 break339340 return response341342 def build_redirect_request(self, request: Request, response: Response) -> Request:343 method = self.redirect_method(request, response)344 url = self.redirect_url(request, response)345 headers = self.redirect_headers(request, url)346 content = self.redirect_content(request, method)347 return Request(method=method, url=url, headers=headers, data=content)348349 def redirect_method(self, request: Request, response: Response) -> str:350 """351 When being redirected we may want to change the method of the request352 based on certain specs or browser behavior.353 """354 method = request.method355356 # https://tools.ietf.org/html/rfc7231#section-6.4.4

Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369

line 357why, one step back
357 if response.status_code == codes.SEE_OTHER and method != "HEAD":

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 358–361why, one step back
358 method = "GET"
359360 # Do what the browsers do, despite standards...361 # Turn 302s into GETs.

Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369

line 362why, one step back
362 if response.status_code == codes.FOUND and method != "HEAD":

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 363–366why, one step back
363 method = "GET"
364365 # If a POST is responded to with a 301, turn it into a GET.366 # This bizarre behaviour is explained in 'requests' issue 1704.

Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369

line 367why, one step back
367 if response.status_code == codes.MOVED_PERMANENTLY and method == "POST":

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 368–410why, one step back
368 method = "GET"
369370 return method371372 def redirect_url(self, request: Request, response: Response) -> URL:373 """374 Return the URL for the redirect to follow.375 """376 location = response.headers["Location"]377378 url = URL(location, allow_relative=True)379380 # Facilitate relative 'Location' headers, as allowed by RFC 7231.381 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')382 if url.is_relative_url:383 url = url.resolve_with(request.url)384385 # Attach previous fragment if needed (RFC 7231 7.1.2)386 if request.url.fragment and not url.fragment:387 url = url.copy_with(fragment=request.url.fragment)388389 return url390391 def redirect_headers(self, request: Request, url: URL) -> Headers:392 """393 Strip Authorization headers when responses are redirected away from394 the origin.395 """396 headers = Headers(request.headers)397 if url.origin != request.url.origin:398 del headers["Authorization"]399 return headers400401 def redirect_content(self, request: Request, method: str) -> bytes:402 """403 Return the body that should be used for the redirect request.404 """405 if method != request.method and method == "GET":406 return b""407 if request.is_streaming:408 raise RedirectBodyUnavailable()409 return request.content410

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 411why, one step back
411 async def close(self) -> None:

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 412why, one step back
412 await self.dispatch.close()

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 413why, one step back
413

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 414why, one step back
414 async def __aenter__(self) -> "AsyncClient":

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 415–423why, one step back
415 return self
416417 async def __aexit__(418 self,419 exc_type: typing.Type[BaseException] = None,420 exc_value: BaseException = None,421 traceback: TracebackType = None,422 ) -> None:423 await self.close()

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 424–428why, one step back
424
425426class Client:427 def __init__(428 self,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 429why, one step back
429 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 430–434why, one step back
430 ssl: SSLConfig = DEFAULT_SSL_CONFIG,
431 timeout: TimeoutConfig = DEFAULT_TIMEOUT_CONFIG,432 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,433 max_redirects: int = DEFAULT_MAX_REDIRECTS,434 dispatch: Dispatcher = None,

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

line 435why, one step back
435 backend: ConcurrencyBackend = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 436–437why, one step back
436 ) -> None:
437 self._client = AsyncClient(

Auth (#65)Tom Christiebefore adoption5afa7dd

line 438why, one step back
438 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 439–443why, one step back
439 ssl=ssl,
440 timeout=timeout,441 pool_limits=pool_limits,442 max_redirects=max_redirects,443 dispatch=dispatch,

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

line 444why, one step back
444 backend=backend,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 445–456why, one step back
445 )
446 self._loop = asyncio.new_event_loop()447448 def request(449 self,450 method: str,451 url: URLTypes,452 *,453 data: RequestData = b"",454 query_params: QueryParamTypes = None,455 headers: HeaderTypes = None,456 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 457why, one step back
457 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 458–468why, one step back
458 allow_redirects: bool = True,
459 ssl: SSLConfig = None,460 timeout: TimeoutConfig = None,461 ) -> SyncResponse:462 request = Request(463 method, url, data=data, query_params=query_params, headers=headers464 )465 self.prepare_request(request)466 response = self.send(467 request,468 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 469why, one step back
469 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 470–482why, one step back
470 allow_redirects=allow_redirects,
471 ssl=ssl,472 timeout=timeout,473 )474 return response475476 def get(477 self,478 url: URLTypes,479 *,480 query_params: QueryParamTypes = None,481 headers: HeaderTypes = None,482 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 483why, one step back
483 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 484–492why, one step back
484 allow_redirects: bool = True,
485 ssl: SSLConfig = None,486 timeout: TimeoutConfig = None,487 ) -> SyncResponse:488 return self.request(489 "GET",490 url,491 headers=headers,492 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 493why, one step back
493 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 494–505why, one step back
494 allow_redirects=allow_redirects,
495 ssl=ssl,496 timeout=timeout,497 )498499 def options(500 self,501 url: URLTypes,502 *,503 query_params: QueryParamTypes = None,504 headers: HeaderTypes = None,505 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 506why, one step back
506 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 507–515why, one step back
507 allow_redirects: bool = True,
508 ssl: SSLConfig = None,509 timeout: TimeoutConfig = None,510 ) -> SyncResponse:511 return self.request(512 "OPTIONS",513 url,514 headers=headers,515 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 516why, one step back
516 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 517–528why, one step back
517 allow_redirects=allow_redirects,
518 ssl=ssl,519 timeout=timeout,520 )521522 def head(523 self,524 url: URLTypes,525 *,526 query_params: QueryParamTypes = None,527 headers: HeaderTypes = None,528 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 529why, one step back
529 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 530–538why, one step back
530 allow_redirects: bool = False, #  Note: Differs to usual default.
531 ssl: SSLConfig = None,532 timeout: TimeoutConfig = None,533 ) -> SyncResponse:534 return self.request(535 "HEAD",536 url,537 headers=headers,538 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 539why, one step back
539 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 540–552why, one step back
540 allow_redirects=allow_redirects,
541 ssl=ssl,542 timeout=timeout,543 )544545 def post(546 self,547 url: URLTypes,548 *,549 data: RequestData = b"",550 query_params: QueryParamTypes = None,551 headers: HeaderTypes = None,552 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 553why, one step back
553 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 554–563why, one step back
554 allow_redirects: bool = True,
555 ssl: SSLConfig = None,556 timeout: TimeoutConfig = None,557 ) -> SyncResponse:558 return self.request(559 "POST",560 url,561 data=data,562 headers=headers,563 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 564why, one step back
564 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 565–577why, one step back
565 allow_redirects=allow_redirects,
566 ssl=ssl,567 timeout=timeout,568 )569570 def put(571 self,572 url: URLTypes,573 *,574 data: RequestData = b"",575 query_params: QueryParamTypes = None,576 headers: HeaderTypes = None,577 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 578why, one step back
578 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 579–588why, one step back
579 allow_redirects: bool = True,
580 ssl: SSLConfig = None,581 timeout: TimeoutConfig = None,582 ) -> SyncResponse:583 return self.request(584 "PUT",585 url,586 data=data,587 headers=headers,588 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 589why, one step back
589 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 590–602why, one step back
590 allow_redirects=allow_redirects,
591 ssl=ssl,592 timeout=timeout,593 )594595 def patch(596 self,597 url: URLTypes,598 *,599 data: RequestData = b"",600 query_params: QueryParamTypes = None,601 headers: HeaderTypes = None,602 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 603why, one step back
603 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 604–613why, one step back
604 allow_redirects: bool = True,
605 ssl: SSLConfig = None,606 timeout: TimeoutConfig = None,607 ) -> SyncResponse:608 return self.request(609 "PATCH",610 url,611 data=data,612 headers=headers,613 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 614why, one step back
614 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 615–627why, one step back
615 allow_redirects=allow_redirects,
616 ssl=ssl,617 timeout=timeout,618 )619620 def delete(621 self,622 url: URLTypes,623 *,624 data: RequestData = b"",625 query_params: QueryParamTypes = None,626 headers: HeaderTypes = None,627 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 628why, one step back
628 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 629–638why, one step back
629 allow_redirects: bool = True,
630 ssl: SSLConfig = None,631 timeout: TimeoutConfig = None,632 ) -> SyncResponse:633 return self.request(634 "DELETE",635 url,636 data=data,637 headers=headers,638 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 639why, one step back
639 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 640–652why, one step back
640 allow_redirects=allow_redirects,
641 ssl=ssl,642 timeout=timeout,643 )644645 def prepare_request(self, request: Request) -> None:646 self._client.prepare_request(request)647648 def send(649 self,650 request: Request,651 *,652 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 653why, one step back
653 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 654–661why, one step back
654 allow_redirects: bool = True,
655 ssl: SSLConfig = None,656 timeout: TimeoutConfig = None,657 ) -> SyncResponse:658 response = self._loop.run_until_complete(659 self._client.send(660 request,661 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 662why, one step back
662 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 663–682why, one step back
663 allow_redirects=allow_redirects,
664 ssl=ssl,665 timeout=timeout,666 )667 )668 return SyncResponse(response, self._loop)669670 def close(self) -> None:671 self._loop.run_until_complete(self._client.close())672673 def __enter__(self) -> "Client":674 return self675676 def __exit__(677 self,678 exc_type: typing.Type[BaseException] = None,679 exc_value: BaseException = None,680 traceback: TracebackType = None,681 ) -> None:682 self.close()