[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
+14 -2
View File
@@ -25,7 +25,7 @@ try:
except ImportError:
REQUESTS_AVAILABLE = False
from .base import Connection
from .base import Connection, _get_client_meta_header, _python_to_meta_version
from ..exceptions import (
ConnectionError,
ImproperlyConfigured,
@@ -142,13 +142,25 @@ class RequestsHttpConnection(Connection):
url = self.base_url + url
headers = headers or {}
if params:
url = "%s?%s" % (url, urlencode(params or {}))
# Pop client metadata from parameters, if any.
client_meta = params.pop("_client_meta", ())
else:
client_meta = ()
if params:
url = "%s?%s" % (url, urlencode(params))
orig_body = body
if self.http_compress and body:
body = self._gzip_compress(body)
headers["content-encoding"] = "gzip"
# Create meta header for requests
if self.meta_header:
client_meta = (
("rq", _python_to_meta_version(requests.__version__)),
) + client_meta
headers["x-elastic-client-meta"] = _get_client_meta_header(client_meta)
start = time.time()
request = requests.Request(method=method, headers=headers, url=url, data=body)
prepared_request = self.session.prepare_request(request)