1
- from typing import Any , Dict , Optional
1
+ from typing import Dict , Iterator , List , Optional , Union
2
2
3
3
from dulwich .client import HTTPUnauthorized , Urllib3HttpGitClient
4
4
@@ -27,10 +27,28 @@ def _http_request(
27
27
self ,
28
28
url : str ,
29
29
headers : Optional [Dict [str , str ]] = None ,
30
- data : Any = None ,
30
+ data : Optional [ Union [ bytes , Iterator [ bytes ]]] = None ,
31
31
):
32
+ cached_chunks : List [bytes ] = []
33
+
34
+ def _cached_data () -> Iterator [bytes ]:
35
+ assert data is not None
36
+ if isinstance (data , bytes ):
37
+ yield data
38
+ return
39
+
40
+ if cached_chunks :
41
+ yield from cached_chunks
42
+ return
43
+
44
+ for chunk in data :
45
+ cached_chunks .append (chunk )
46
+ yield chunk
47
+
32
48
try :
33
- result = super ()._http_request (url , headers = headers , data = data )
49
+ result = super ()._http_request (
50
+ url , headers = headers , data = None if data is None else _cached_data ()
51
+ )
34
52
except HTTPUnauthorized :
35
53
auth_header = self ._get_auth ()
36
54
if not auth_header :
@@ -39,7 +57,9 @@ def _http_request(
39
57
headers .update (auth_header )
40
58
else :
41
59
headers = auth_header
42
- result = super ()._http_request (url , headers = headers , data = data )
60
+ result = super ()._http_request (
61
+ url , headers = headers , data = None if data is None else _cached_data ()
62
+ )
43
63
if self ._store_credentials is not None :
44
64
self ._store_credentials .approve ()
45
65
return result
0 commit comments