-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Client base_url #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client base_url #46
Conversation
lovelydinosaur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
A few tweaks requested here, since we ought to use the URL class internally (since it'll correctly deal with stuff like internationalized URLs for us).
httpcore/client.py
Outdated
| class Client: | ||
| def __init__( | ||
| self, | ||
| base_url: str = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd want to use URLTypes here.
httpcore/client.py
Outdated
| ) | ||
| self.adapter = EnvironmentAdapter(dispatch=redirect_adapter) | ||
|
|
||
| self.base_url = base_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the URL type. Eg. self.base_url = None if url is None else URL(base_url)
httpcore/client.py
Outdated
| ) -> Response: | ||
|
|
||
| if self.base_url is not None: | ||
| url = urljoin(self.base_url, url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be something like...
if self.base_url is not None:
url = URL(url, allow_relative=True).resolve_with(self.base_url)
tests/test_client.py
Outdated
| response = await client.get(path) | ||
| assert response.status_code == 200 | ||
| assert response.text == "Hello, world!" | ||
| assert str(response.request.url) == "http://127.0.0.1:8000/hello/hummans/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just have a single example in the test case, and use http://127.0.0.1:8000/ as the base URL, and just do .get('/hello') or something like that.
(Also just use str(response.url) instead of str(response.request.url))
|
On reflection I think we should punt on this for now. |
ref #38