File tree 4 files changed +21
-1
lines changed
4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project are documented in this file.
5
5
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
6
6
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) (as of version 1.5.0).
7
7
8
+ ## [ 1.6.3] - 2022-08-02
9
+
10
+ ### Added
11
+
12
+ - ` download.stream_file() ` supports passing ` headers ` (scrapers were already using it)
13
+
8
14
## [ 1.6.2] - 2022-07-29
9
15
10
16
### Changed
Original file line number Diff line number Diff line change 1
- 1.6.2
1
+ 1.6.3
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ def stream_file(
165
165
proxies : Optional [dict ] = None ,
166
166
only_first_block : Optional [bool ] = False ,
167
167
max_retries : Optional [int ] = 5 ,
168
+ headers : Optional [Dict [str , str ]] = None ,
168
169
) -> Union [int , requests .structures .CaseInsensitiveDict ]:
169
170
"""Stream data from a URL to either a BytesIO object or a file
170
171
Arguments -
@@ -188,6 +189,7 @@ def stream_file(
188
189
url ,
189
190
stream = True ,
190
191
proxies = proxies ,
192
+ headers = headers ,
191
193
)
192
194
resp .raise_for_status ()
193
195
Original file line number Diff line number Diff line change @@ -65,6 +65,18 @@ def test_first_block_download(valid_http_url):
65
65
assert len (byte_stream .read ()) <= expected
66
66
67
67
68
+ @pytest .mark .slow
69
+ def test_user_agent ():
70
+ ua = "zimscraperlib-test"
71
+ byte_stream = io .BytesIO ()
72
+ stream_file (
73
+ url = "http://useragentstring.com/" ,
74
+ byte_stream = byte_stream ,
75
+ headers = {"User-Agent" : "zimscraperlib-test" },
76
+ )
77
+ assert ua in byte_stream .read ().decode ("utf-8" )
78
+
79
+
68
80
@pytest .mark .slow
69
81
def test_save_http (tmp_path , valid_http_url ):
70
82
dest_file = tmp_path / "favicon.ico"
You can’t perform that action at this time.
0 commit comments