server/net: make the user-agent configurable

Fixes #127
This commit is contained in:
rr-
2017-03-03 17:24:58 +01:00
parent e087b83082
commit 5681fd11ef
3 changed files with 8 additions and 1 deletions

View File

@ -1,10 +1,13 @@
import urllib.request
from szurubooru import config
from szurubooru import errors
def download(url: str) -> bytes:
assert url
request = urllib.request.Request(url)
if config.config['user_agent']:
request.add_header('User-Agent', config.config['user_agent'])
request.add_header('Referer', url)
try:
with urllib.request.urlopen(request) as handle:

View File

@ -1,7 +1,10 @@
from szurubooru.func import net
def test_download():
def test_download(config_injector):
config_injector({
'user_agent': None
})
url = 'http://info.cern.ch/hypertext/WWW/TheProject.html'
expected_content = (