diff --git a/src/webdav4/client.py b/src/webdav4/client.py index bb430cd..9c02e94 100644 --- a/src/webdav4/client.py +++ b/src/webdav4/client.py @@ -647,10 +647,13 @@ def upload_fileobj( # noqa: PLR0913 chunk_size: Optional[int] = None, size: Optional[int] = None, headers: Optional[Dict[str, str]] = None, + request_kwargs: Optional[Dict[str, Any]] = None, ) -> None: """Upload file from file object to given path.""" if headers is None: headers = {} + if request_kwargs is None: + request_kwargs = {} # we try to avoid chunked transfer as much as possible # so we try to use size as a hint if provided. @@ -670,6 +673,6 @@ def upload_fileobj( # noqa: PLR0913 content = read_chunks(wrapped, chunk_size=chunk_size or self.chunk_size) http_resp = self.request( - HTTPMethod.PUT, to_path, content=content, headers=headers + HTTPMethod.PUT, to_path, content=content, headers=headers, **request_kwargs ) http_resp.raise_for_status() diff --git a/tests/test_client.py b/tests/test_client.py index 50e9fb4..fc434d5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -9,7 +9,7 @@ from unittest.mock import MagicMock, patch import pytest -from httpx import Request, Response +from httpx import Request, Response, Timeout from webdav4.client import ( BadGatewayError, @@ -691,6 +691,13 @@ def test_upload_fobj_size_hints(client: Client): client.upload_fileobj(wrapped, "foobar", size=6) # type: ignore assert m.call_args[1]["headers"] == {"Content-Length": "6"} + client.upload_fileobj( + BytesIO(b"foobar"), + "foobar", + request_kwargs={"timeout": Timeout(3, connect=10)}, + ) + assert m.call_args[1]["timeout"] == Timeout(connect=10, read=3, write=3, pool=3) + def test_upload_file(tmp_path: Path, storage_dir: TmpDir, client: Client): """Test uploading a local file to a remote."""