parent
							
								
									e087b83082
								
							
						
					
					
						commit
						5681fd11ef
					
				@ -10,6 +10,7 @@ api_url: # where frontend connects to, example: http://api.example.com/
 | 
			
		||||
base_url: # used to form links to frontend, example: http://example.com/
 | 
			
		||||
data_url: # used to form links to posts and avatars, example: http://example.com/data/
 | 
			
		||||
data_dir: # absolute path for posts and avatars storage, example: /srv/www/booru/client/public/data/
 | 
			
		||||
user_agent: # user agent name used to download files from the web on behalf of the api users
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# usage: schema://user:password@host:port/database_name
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -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 = (
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user