|
17 | 17 | # under the License.
|
18 | 18 |
|
19 | 19 | import ssl
|
| 20 | +import re |
20 | 21 | import gzip
|
21 | 22 | import io
|
22 | 23 | from mock import patch
|
@@ -316,3 +317,43 @@ async def test_surrogatepass_into_bytes(self):
|
316 | 317 | con = await self._get_mock_connection(response_body=buf)
|
317 | 318 | status, headers, data = await con.perform_request("GET", "/")
|
318 | 319 | assert u"你好\uda6a" == data
|
| 320 | + |
| 321 | + async def test_meta_header_value(self): |
| 322 | + con = await self._get_mock_connection() |
| 323 | + assert con.meta_header is True |
| 324 | + |
| 325 | + await con.perform_request("GET", "/", body=b"{}") |
| 326 | + |
| 327 | + _, kwargs = con.session.request.call_args |
| 328 | + headers = kwargs["headers"] |
| 329 | + assert re.match( |
| 330 | + r"^es=[0-9]+\.[0-9]+\.[0-9]+p?,py=[0-9]+\.[0-9]+\.[0-9]+p?," |
| 331 | + r"t=[0-9]+\.[0-9]+\.[0-9]+p?,ai=[0-9]+\.[0-9]+\.[0-9]+p?$", |
| 332 | + headers["x-elastic-client-meta"], |
| 333 | + ) |
| 334 | + |
| 335 | + con = await self._get_mock_connection() |
| 336 | + assert con.meta_header is True |
| 337 | + |
| 338 | + await con.perform_request( |
| 339 | + "GET", "/", body=b"{}", params={"_client_meta": (("h", "bp"),)} |
| 340 | + ) |
| 341 | + |
| 342 | + (method, url), kwargs = con.session.request.call_args |
| 343 | + headers = kwargs["headers"] |
| 344 | + assert method == "GET" |
| 345 | + assert str(url) == "http://localhost:9200/" |
| 346 | + assert re.match( |
| 347 | + r"^es=[0-9]+\.[0-9]+\.[0-9]+p?,py=[0-9]+\.[0-9]+\.[0-9]+p?," |
| 348 | + r"t=[0-9]+\.[0-9]+\.[0-9]+p?,ai=[0-9]+\.[0-9]+\.[0-9]+p?,h=bp$", |
| 349 | + headers["x-elastic-client-meta"], |
| 350 | + ) |
| 351 | + |
| 352 | + con = await self._get_mock_connection(connection_params={"meta_header": False}) |
| 353 | + assert con.meta_header is False |
| 354 | + |
| 355 | + await con.perform_request("GET", "/", body=b"{}") |
| 356 | + |
| 357 | + _, kwargs = con.session.request.call_args |
| 358 | + headers = kwargs["headers"] |
| 359 | + assert "x-elastic-client-meta" not in (x.lower() for x in headers) |
0 commit comments