[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(
|
||||
|
||||
Reference in New Issue
Block a user