Absolute URLs identified as relative #1876
Replies: 4 comments
-
|
It may also be a good idea to expose the mounting mechanism to allow easy addition or modification of transports to instances. # _client.py
class Client(BaseClient):
...
def mount(self, pattern: str, transport: BaseTransport) -> None:
self._mounts.update({URLPattern(pattern): transport})import httpx
client = httpx.Client()
client.mount('http://*.onion', httpx.BaseTransport())
print(client._mounts)
#> {<httpx._utils.URLPattern object at ...>: <httpx.BaseTransport object at ...>}
|
Beta Was this translation helpful? Give feedback.
-
|
I'm running into the same problem (with the same use-case). +1 for making an issue for this. Update: I gave your patch a shot, but the test suite fails in unexpected ways and it's turtles all the way down. Ultimately, I ended up finding trouble in httpcore/trio. The better fix (that doesn't break all sorts of expectations from the rest of httpx) is: @property
def is_absolute_url(self) -> bool:
"""
Return `True` for absolute URLs such as 'http://example.com/path',
and `False` for relative URLs such as '/path'.
"""
# We work around `.is_absolute` from `rfc3986` because it treats
# URLs with a fragment portion as not absolute.
# What we actually care about is if the URL provides
# a scheme and hostname to which connections should be made.
return self._uri_reference.copy_with(fragment=None).is_absolute()
@property
def is_relative_url(self) -> bool:
"""
Return `False` for absolute URLs such as 'http://example.com/path',
and `True` for relative URLs such as '/path'.
"""
return not self.is_absolute_urlI've got a patch ready at https://github.com/stijn-devriendt/httpx/tree/fix-incorrect-relative-url that keeps things running. |
Beta Was this translation helpful? Give feedback.
-
|
Is anything happening with this? |
Beta Was this translation helpful? Give feedback.
-
|
Unfortunately I am hitting the same issue above for the same usecase and would prefer not to patch these functions within httpx. Wanted to bump this discussion and see if there were any plans to fix this behavior in a future release, or other workarounds that could be used in the meantime? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I'm trying to implement a
file://transport and I've just found an unexpected behavior in the URL parsing.This is indeed not the case and causes
BaseClient._merge_urlto remove the URL's scheme.Related to this, there's also an improper error handling for HTTP URLs without host:
I agree with the rationale in
URL.is_absolute_urlbut a URL with a scheme or a host should not be considered as relativehttpx/httpx/_models.py
Lines 390 to 400 in e1abaf1
I think this could be fixed with very little change and without collateral damage:
If you consider it appropriate I'd be happy to open an issue and make a PR.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions