mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-04 22:40:29 +03:00
set F-Droid HTTP Headers globally
This commit is contained in:
parent
ab2291475b
commit
733e7be1b3
1 changed files with 5 additions and 5 deletions
|
|
@ -17,16 +17,17 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
HEADERS = {'User-Agent': 'F-Droid'}
|
||||||
|
|
||||||
|
|
||||||
def download_file(url, local_filename=None, dldir='tmp'):
|
def download_file(url, local_filename=None, dldir='tmp'):
|
||||||
filename = url.split('/')[-1]
|
filename = url.split('/')[-1]
|
||||||
if local_filename is None:
|
if local_filename is None:
|
||||||
local_filename = os.path.join(dldir, filename)
|
local_filename = os.path.join(dldir, filename)
|
||||||
# the stream=True parameter keeps memory usage low
|
# the stream=True parameter keeps memory usage low
|
||||||
r = requests.get(url, stream=True, allow_redirects=True)
|
r = requests.get(url, stream=True, allow_redirects=True, headers=HEADERS)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
with open(local_filename, 'wb') as f:
|
with open(local_filename, 'wb') as f:
|
||||||
for chunk in r.iter_content(chunk_size=1024):
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
|
@ -48,16 +49,15 @@ def http_get(url, etag=None, timeout=600):
|
||||||
- The raw content that was downloaded or None if it did not change
|
- The raw content that was downloaded or None if it did not change
|
||||||
- The new eTag as returned by the HTTP request
|
- The new eTag as returned by the HTTP request
|
||||||
"""
|
"""
|
||||||
headers = {'User-Agent': 'F-Droid'}
|
|
||||||
# TODO disable TLS Session IDs and TLS Session Tickets
|
# TODO disable TLS Session IDs and TLS Session Tickets
|
||||||
# (plain text cookie visible to anyone who can see the network traffic)
|
# (plain text cookie visible to anyone who can see the network traffic)
|
||||||
if etag:
|
if etag:
|
||||||
r = requests.head(url, headers=headers, timeout=timeout)
|
r = requests.head(url, headers=HEADERS, timeout=timeout)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
if 'ETag' in r.headers and etag == r.headers['ETag']:
|
if 'ETag' in r.headers and etag == r.headers['ETag']:
|
||||||
return None, etag
|
return None, etag
|
||||||
|
|
||||||
r = requests.get(url, headers=headers, timeout=timeout)
|
r = requests.get(url, headers=HEADERS, timeout=timeout)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
new_etag = None
|
new_etag = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue