[7.x] Add the 'X-Elastic-Client-Meta' header
Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
co-authored by
Seth Michael Larson
parent
2e06989ca1
commit
b894e359df
@@ -22,7 +22,11 @@ import urllib3 # type: ignore
|
||||
import warnings
|
||||
from ._extra_imports import aiohttp_exceptions, aiohttp, yarl
|
||||
from .compat import get_running_loop
|
||||
from ..connection import Connection
|
||||
from ..connection.base import (
|
||||
Connection,
|
||||
_get_client_meta_header,
|
||||
_python_to_meta_version,
|
||||
)
|
||||
from ..compat import urlencode
|
||||
from ..exceptions import (
|
||||
ConnectionError,
|
||||
@@ -218,6 +222,11 @@ class AIOHttpConnection(AsyncConnection):
|
||||
|
||||
orig_body = body
|
||||
url_path = self.url_prefix + url
|
||||
if params:
|
||||
# Pop client metadata from parameters, if any.
|
||||
client_meta = tuple(params.pop("_client_meta", ()))
|
||||
else:
|
||||
client_meta = ()
|
||||
if params:
|
||||
query_string = urlencode(params)
|
||||
else:
|
||||
@@ -268,6 +277,13 @@ class AIOHttpConnection(AsyncConnection):
|
||||
body = self._gzip_compress(body)
|
||||
req_headers["content-encoding"] = "gzip"
|
||||
|
||||
# Create meta header for aiohttp
|
||||
if self.meta_header:
|
||||
client_meta = (
|
||||
("ai", _python_to_meta_version(aiohttp.__version__)),
|
||||
) + client_meta
|
||||
req_headers["x-elastic-client-meta"] = _get_client_meta_header(client_meta)
|
||||
|
||||
start = self.loop.time()
|
||||
try:
|
||||
async with self.session.request(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
from ._extra_imports import aiohttp # type: ignore
|
||||
from typing import Optional, Mapping, Collection, Union, Any, Tuple
|
||||
from typing import Optional, Mapping, MutableMapping, Collection, Union, Any, Tuple
|
||||
from ..connection import Connection
|
||||
|
||||
class AsyncConnection(Connection):
|
||||
@@ -24,11 +24,11 @@ class AsyncConnection(Connection):
|
||||
self,
|
||||
method: str,
|
||||
url: str,
|
||||
params: Optional[Mapping[str, Any]] = ...,
|
||||
params: Optional[MutableMapping[str, Any]] = ...,
|
||||
body: Optional[bytes] = ...,
|
||||
timeout: Optional[Union[int, float]] = ...,
|
||||
ignore: Collection[int] = ...,
|
||||
headers: Optional[Mapping[str, str]] = ...,
|
||||
headers: Optional[MutableMapping[str, str]] = ...,
|
||||
) -> Tuple[int, Mapping[str, str], str]: ...
|
||||
async def close(self) -> None: ...
|
||||
|
||||
@@ -55,6 +55,7 @@ class AIOHttpConnection(AsyncConnection):
|
||||
cloud_id: Optional[str] = ...,
|
||||
api_key: Optional[Any] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
meta_header: bool = ...,
|
||||
loop: Any = ...,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user