Skip to content

Commit c7c5a71

Browse files
committed
fix(core): preserve query strings in HTTP wait URLs
1 parent 6146aa1 commit c7c5a71

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎src/testcontainers/core/wait_strategies.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ def from_url(cls, url: str) -> Self:
206206
Example:
207207
strategy = HttpWaitStrategy.from_url("https://localhost:8080/api/health")
208208
"""
209-
from urllib.parse import urlparse
209+
from urllib.parse import urlsplit
210210

211-
parsed = urlparse(url)
211+
parsed = urlsplit(url)
212212
port = parsed.port or (443 if parsed.scheme == "https" else 80)
213213
path = parsed.path or "/"
214+
if parsed.query:
215+
path += f"?{parsed.query}"
214216

215217
strategy = cls(port, path)
216218

‎tests/core/test_wait_strategies.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ def test_from_url(self, url, expected_port, expected_path, expected_tls):
364364
assert strategy._path == expected_path
365365
assert strategy._tls is expected_tls
366366

367+
@pytest.mark.parametrize(
368+
"url,expected_path",
369+
[
370+
("http://localhost:8080/health?ready=true", "/health?ready=true"),
371+
("http://localhost:8080?ready=true", "/?ready=true"),
372+
("https://localhost/health?a=1&a=2&empty=", "/health?a=1&a=2&empty="),
373+
("http://localhost/health?value=a%23b%26c#ignored", "/health?value=a%23b%26c"),
374+
("http://localhost/health;version=2?ready=true", "/health;version=2?ready=true"),
375+
],
376+
)
377+
def test_from_url_preserves_request_target(self, url, expected_path):
378+
strategy = HttpWaitStrategy.from_url(url)
379+
assert strategy._path == expected_path
380+
367381
@pytest.mark.parametrize(
368382
"status_codes,expected_result",
369383
[

0 commit comments

Comments
 (0)