Non-blocking HTTP client with no external dependencies. This class implements an HTTP 1.1 client on top of Tornado's IOStreams. Some features found in the curl-based AsyncHTTPClient are not yet supported. In particular, proxies are not supported, connections are not reused, and cal
| 77 | |
| 78 | |
| 79 | class SimpleAsyncHTTPClient(AsyncHTTPClient): |
| 80 | """Non-blocking HTTP client with no external dependencies. |
| 81 | |
| 82 | This class implements an HTTP 1.1 client on top of Tornado's IOStreams. |
| 83 | Some features found in the curl-based AsyncHTTPClient are not yet |
| 84 | supported. In particular, proxies are not supported, connections |
| 85 | are not reused, and callers cannot select the network interface to be |
| 86 | used. |
| 87 | |
| 88 | This implementation supports the following arguments, which can be passed |
| 89 | to ``configure()`` to control the global singleton, or to the constructor |
| 90 | when ``force_instance=True``. |
| 91 | |
| 92 | ``max_clients`` is the number of concurrent requests that can be |
| 93 | in progress; when this limit is reached additional requests will be |
| 94 | queued. Note that time spent waiting in this queue still counts |
| 95 | against the ``request_timeout``. |
| 96 | |
| 97 | ``defaults`` is a dict of parameters that will be used as defaults on all |
| 98 | `.HTTPRequest` objects submitted to this client. |
| 99 | |
| 100 | ``hostname_mapping`` is a dictionary mapping hostnames to IP addresses. |
| 101 | It can be used to make local DNS changes when modifying system-wide |
| 102 | settings like ``/etc/hosts`` is not possible or desirable (e.g. in |
| 103 | unittests). ``resolver`` is similar, but using the `.Resolver` interface |
| 104 | instead of a simple mapping. |
| 105 | |
| 106 | ``max_buffer_size`` (default 100MB) is the number of bytes |
| 107 | that can be read into memory at once. ``max_body_size`` |
| 108 | (defaults to ``max_buffer_size``) is the largest response body |
| 109 | that the client will accept. Without a |
| 110 | ``streaming_callback``, the smaller of these two limits |
| 111 | applies; with a ``streaming_callback`` only ``max_body_size`` |
| 112 | does. |
| 113 | |
| 114 | .. versionchanged:: 4.2 |
| 115 | Added the ``max_body_size`` argument. |
| 116 | """ |
| 117 | |
| 118 | def initialize( # type: ignore |
| 119 | self, |
| 120 | max_clients: int = 10, |
| 121 | hostname_mapping: Optional[Dict[str, str]] = None, |
| 122 | max_buffer_size: int = 104857600, |
| 123 | resolver: Optional[Resolver] = None, |
| 124 | defaults: Optional[Dict[str, Any]] = None, |
| 125 | max_header_size: Optional[int] = None, |
| 126 | max_body_size: Optional[int] = None, |
| 127 | ) -> None: |
| 128 | super().initialize(defaults=defaults) |
| 129 | self.max_clients = max_clients |
| 130 | self.queue = ( |
| 131 | collections.deque() |
| 132 | ) # type: Deque[Tuple[object, HTTPRequest, Callable[[HTTPResponse], None]]] |
| 133 | self.active = ( |
| 134 | {} |
| 135 | ) # type: Dict[object, Tuple[HTTPRequest, Callable[[HTTPResponse], None]]] |
| 136 | self.waiting = ( |
no outgoing calls