[7.x] Add the 'X-Elastic-Client-Meta' header

Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
github-actions[bot]
2020-12-14 17:50:14 -06:00
committed by GitHub
co-authored by Seth Michael Larson
parent 2e06989ca1
commit b894e359df
12 changed files with 269 additions and 12 deletions
+17 -1
View File
@@ -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(