-
Notifications
You must be signed in to change notification settings - Fork 26
Default base_url for HTTP Client #403
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -180,6 +180,11 @@ def __init__( | |||||
| ) | ||||||
|
|
||||||
| self.allHeaders = self._build_headers(create_model_instance(Options)) | ||||||
| if http_client: | ||||||
| http_client.base_url = ( | ||||||
| http_client.base_url if http_client.base_url != "" else self.base_url | ||||||
| ) | ||||||
|
|
||||||
| self._client = http_client or httpx.Client( | ||||||
| base_url=self.base_url, | ||||||
| headers={ | ||||||
|
|
@@ -895,6 +900,10 @@ def __init__( | |||||
| ) | ||||||
|
|
||||||
| self.allHeaders = self._build_headers(create_model_instance(Options)) | ||||||
| if http_client: | ||||||
| http_client.base_url = ( | ||||||
| http_client.base_url if http_client.base_url != "" else self.base_url | ||||||
|
||||||
| http_client.base_url if http_client.base_url != "" else self.base_url | |
| http_client.base_url if (http_client.base_url and str(http_client.base_url) != "") else self.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.
The comparison
http_client.base_url != \"\"may not correctly handle all cases where base_url is unset. HTTPX's base_url is a URL object, not a string, and when unset it defaults to an empty URL object (which doesn't equal an empty string). Consider usingif not http_client.base_url or str(http_client.base_url) == \"\"for a more robust check.