File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Expand file tree Collapse file tree 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.
55The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
66and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) (as of version 1.5.0).
77
8+ ## [ 1.6.3] - 2022-08-02
9+
10+ ### Added
11+
12+ - ` download.stream_file() ` supports passing ` headers ` (scrapers were already using it)
13+
814## [ 1.6.2] - 2022-07-29
915
1016### 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(
165165 proxies : Optional [dict ] = None ,
166166 only_first_block : Optional [bool ] = False ,
167167 max_retries : Optional [int ] = 5 ,
168+ headers : Optional [Dict [str , str ]] = None ,
168169) -> Union [int , requests .structures .CaseInsensitiveDict ]:
169170 """Stream data from a URL to either a BytesIO object or a file
170171 Arguments -
@@ -188,6 +189,7 @@ def stream_file(
188189 url ,
189190 stream = True ,
190191 proxies = proxies ,
192+ headers = headers ,
191193 )
192194 resp .raise_for_status ()
193195
Original file line number Diff line number Diff line change @@ -65,6 +65,18 @@ def test_first_block_download(valid_http_url):
6565 assert len (byte_stream .read ()) <= expected
6666
6767
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+
6880@pytest .mark .slow
6981def test_save_http (tmp_path , valid_http_url ):
7082 dest_file = tmp_path / "favicon.ico"
You can’t perform that action at this time.
0 commit comments