Skip to content

Commit

Permalink
Add http_client parameter to Client (vaphes#43)
Browse files Browse the repository at this point in the history
* Add http_client parameter to Client

This will allow users to pass their own http client
potentially with custom headers and other settings.

* update dev requirements
  • Loading branch information
abyesilyurt authored Jun 2, 2023
1 parent 4ff17b4 commit 82a5b39
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 206 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install poetry
python -m poetry install --with dev
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
poetry run pytest
4 changes: 3 additions & 1 deletion pocketbase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ def __init__(
lang: str = "en-US",
auth_store: BaseAuthStore | None = None,
timeout: float = 120,
http_client: httpx.Client | None = None,
) -> None:
self.base_url = base_url
self.lang = lang
self.auth_store = auth_store or BaseAuthStore() # LocalAuthStore()
self.timeout = timeout
self.http_client = http_client or httpx.Client()
# services
self.admins = AdminService(self)
self.collections = CollectionService(self)
Expand Down Expand Up @@ -88,7 +90,7 @@ def send(self, path: str, req_config: dict[str:Any]) -> Any:
files = None
data = None
try:
response = httpx.request(
response = self.http_client.request(
method=method,
url=url,
params=params,
Expand Down
Loading

0 comments on commit 82a5b39

Please sign in to comment.