Skip to content

Commit 85e1112

Browse files
committed
Add support for httpx authentication class
1 parent f42e1ab commit 85e1112

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

elastic_transport/_node/_http_httpx.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,22 @@ def __init__(self, config: NodeConfig):
101101
elif config.client_cert:
102102
ssl_context.load_cert_chain(config.client_cert)
103103

104+
# Httpx supports setting 'auth' via _extras['requests.session.auth'] = ...
105+
# The naming is weird but it enables compatibility with the existing
106+
# 'requests.session.auth' parameter
107+
try:
108+
httpx_auth: Optional[httpx.Auth] = config._extras.pop(
109+
"requests.session.auth", None
110+
)
111+
except AttributeError:
112+
httpx_auth = None
113+
104114
self.client = httpx.AsyncClient(
105115
base_url=f"{config.scheme}://{config.host}:{config.port}",
106116
limits=httpx.Limits(max_connections=config.connections_per_node),
107117
verify=ssl_context or False,
108118
timeout=config.request_timeout,
119+
auth=httpx_auth,
109120
)
110121

111122
async def perform_request( # type: ignore[override]

0 commit comments

Comments
 (0)