Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elastic_transport/_node/_http_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, config: NodeConfig):
ssl_context.load_cert_chain(config.client_cert)

self.client = httpx.AsyncClient(
base_url=f"{config.scheme}://{config.host}:{config.port}",
base_url=f"{config.scheme}://{config.host}:{config.port}{config.path_prefix}",
limits=httpx.Limits(max_connections=config.connections_per_node),
verify=ssl_context or False,
timeout=config.request_timeout,
Expand Down
12 changes: 12 additions & 0 deletions tests/node/test_http_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ def test_ca_certs_with_verify_ssl_false_raises_error(self):
str(exc.value) == "You cannot use 'ca_certs' when 'verify_certs=False'"
)

def test_path_prefix(self):
node = create_node(
NodeConfig(
"http",
"localhost",
9200,
path_prefix="/test",
)
)
assert node.base_url == "http://localhost:9200/test"
assert node.client.base_url == "http://localhost:9200/test/"


@pytest.mark.anyio
class TestHttpxAsyncNode:
Expand Down
11 changes: 11 additions & 0 deletions tests/node/test_http_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,14 @@ def test_requests_custom_auth(self):
node.perform_request("GET", "/")
(request,), _ = node.session.send.call_args
assert request.headers["authorization"] == "Basic dXNlcm5hbWU6cGFzc3dvcmQ="

def test_path_prefix(self):
node = self._get_mock_node(
NodeConfig(
"http",
"localhost",
9200,
path_prefix="/test",
)
)
assert node.base_url == "http://localhost:9200/test"