Repository navigation
Replies: 2 comments
Personally I think it's a misdesign, and that Including a path prefix is always confusing because it's non-obvious if the behaviour will be a strict URL join or some form of URL append. Eg. what behavior is expected for... client = Client(base_url="https://www.example.com/that")
response = client.get("/this")
Yeah it's a confusing part of the API, and yes it does look like you've found yourself a corner-case bit of particularly broken behavior. |
|
I reproduced your exact result on HTTPX 0.28.1. There are two steps behind the missing
Thus the URL parsing is understandable, but the client merge gives the corner-case behavior @lovelydinosaur identified. It is also different from standard For the typo in your example, use one leading slash or none: import httpx
with httpx.Client(base_url="http://127.0.0.1:8282/Foo", trust_env=False) as client:
for path in ("/foobar/dev03/image.jpeg", "foobar/dev03/image.jpeg"):
request = client.build_request("GET", path)
assert str(request.url) == (
"http://127.0.0.1:8282/Foo/foobar/dev03/image.jpeg"
)
# If foobar really is the destination host, supply the scheme explicitly.
request = client.build_request("GET", "http://foobar/dev03/image.jpeg")
assert str(request.url) == "http://foobar/dev03/image.jpeg"The single leading slash above still preserves AI assistance: Codex. The parsing assertions, your original URL, both corrected paths, and the explicit-host case were checked with HTTPX 0.28.1 / Python 3.12.3. These tests only build requests; they do not send traffic or claim that the library has been fixed. |
Uh oh!
There was an error while loading. Please reload this page.
I was soo perplexed by this until I realized that httpx was ignoring part of the path that was used to build the request.
The client was built with the following:
Then I built a request using the following:
This was indeed a typo, which I didn't see at the time. However, it turns out that when this request is built, the url turns out to be:
It has essentially stripped off the
//foobarpart. I was quite confused for some time why it does that, until I started debugging.Is this a bug, or expected behavior? I certainly didn't expect it.
All reactions