Skip to content

Commit af9515b

Browse files
authored
Add explicit parameters for AIOHttpConnection and AsyncTransport
1 parent 74320f4 commit af9515b

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

elasticsearch/_async/http_aiohttp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(
7777
self,
7878
host="localhost",
7979
port=None,
80+
url_prefix="",
81+
timeout=10,
8082
http_auth=None,
8183
use_ssl=False,
8284
verify_certs=VERIFY_CERTS_DEFAULT,
@@ -138,6 +140,8 @@ def __init__(
138140
super().__init__(
139141
host=host,
140142
port=port,
143+
url_prefix=url_prefix,
144+
timeout=timeout,
141145
use_ssl=use_ssl,
142146
headers=headers,
143147
http_compress=http_compress,

elasticsearch/_async/http_aiohttp.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class AIOHttpConnection(AsyncConnection):
4141
self,
4242
host: str = ...,
4343
port: Optional[int] = ...,
44+
url_prefix: str = ...,
45+
timeout: int = ...,
4446
http_auth: Optional[Any] = ...,
4547
use_ssl: bool = ...,
4648
verify_certs: bool = ...,

elasticsearch/_async/transport.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
import sys
2121
from itertools import chain
2222

23+
from ..connection_pool import ConnectionPool
2324
from ..exceptions import (
2425
ConnectionError,
2526
ConnectionTimeout,
2627
SerializationError,
2728
TransportError,
2829
UnsupportedProductError,
2930
)
30-
from ..transport import Transport
31+
from ..serializer import JSONSerializer
32+
from ..transport import Transport, get_host_info
3133
from .compat import get_running_loop
3234
from .http_aiohttp import AIOHttpConnection
3335

@@ -44,7 +46,26 @@ class AsyncTransport(Transport):
4446

4547
DEFAULT_CONNECTION_CLASS = AIOHttpConnection
4648

47-
def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
49+
def __init__(
50+
self,
51+
hosts,
52+
connection_class=None,
53+
connection_pool_class=ConnectionPool,
54+
host_info_callback=get_host_info,
55+
sniff_on_start=False,
56+
sniffer_timeout=None,
57+
sniff_timeout=0.1,
58+
sniff_on_connection_fail=False,
59+
serializer=JSONSerializer(),
60+
serializers=None,
61+
default_mimetype="application/json",
62+
max_retries=3,
63+
retry_on_status=(502, 503, 504),
64+
retry_on_timeout=False,
65+
send_get_body_as="GET",
66+
meta_header=True,
67+
**kwargs
68+
):
4869
"""
4970
:arg hosts: list of dictionaries, each containing keyword arguments to
5071
create a `connection_class` instance
@@ -77,6 +98,8 @@ def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
7798
don't support passing bodies with GET requests. If you set this to
7899
'POST' a POST method will be used instead, if to 'source' then the body
79100
will be serialized and passed as a query parameter `source`.
101+
:arg meta_header: If True will send the 'X-Elastic-Client-Meta' HTTP header containing
102+
simple client metadata. Setting to False will disable the header. Defaults to True.
80103
81104
Any extra keyword arguments will be passed to the `connection_class`
82105
when creating and instance unless overridden by that connection's
@@ -88,7 +111,23 @@ def __init__(self, hosts, *args, sniff_on_start=False, **kwargs):
88111
self._sniff_on_start_event = None # type: asyncio.Event
89112

90113
super(AsyncTransport, self).__init__(
91-
*args, hosts=[], sniff_on_start=False, **kwargs
114+
hosts=[],
115+
connection_class=connection_class,
116+
connection_pool_class=connection_pool_class,
117+
host_info_callback=host_info_callback,
118+
sniff_on_start=False,
119+
sniffer_timeout=sniffer_timeout,
120+
sniff_timeout=sniff_timeout,
121+
sniff_on_connection_fail=sniff_on_connection_fail,
122+
serializer=serializer,
123+
serializers=serializers,
124+
default_mimetype=default_mimetype,
125+
max_retries=max_retries,
126+
retry_on_status=retry_on_status,
127+
retry_on_timeout=retry_on_timeout,
128+
send_get_body_as=send_get_body_as,
129+
meta_header=meta_header,
130+
**kwargs,
92131
)
93132

94133
# Don't enable sniffing on Cloud instances.

elasticsearch/_async/transport.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class AsyncTransport(object):
6363
retry_on_status: Collection[int] = ...,
6464
retry_on_timeout: bool = ...,
6565
send_get_body_as: str = ...,
66+
meta_header: bool = ...,
6667
**kwargs: Any
6768
) -> None: ...
6869
def add_connection(self, host: Any) -> None: ...

0 commit comments

Comments
 (0)