pull/30/head
hunsh 4 years ago
parent 737e892b75
commit 67b6b9b4b7

@ -105,21 +105,15 @@ def proxy(u):
if exp2.match(u): if exp2.match(u):
u = u.replace('/blob/', '/raw/', 1) u = u.replace('/blob/', '/raw/', 1)
headers = {} headers = {}
r_headers = {} r_headers = dict(request.headers)
for i in ['Range', 'User-Agent', 'Accept', 'Content-Type', 'Content-Encoding']: if 'Host' in r_headers:
if i in request.headers: r_headers.pop('Host')
r_headers[i] = request.headers.get(i)
r_headers['Accept-Encoding'] = request.headers.get('Accept-Encoding', 'identity')
try: try:
url = u + request.url.replace(request.base_url, '', 1) url = u + request.url.replace(request.base_url, '', 1)
if url.startswith('https:/') and not url.startswith('https://'): if url.startswith('https:/') and not url.startswith('https://'):
url = 'https://' + url[7:] url = 'https://' + url[7:]
r = requests.request(method=request.method, url=url, data=request.data, headers=r_headers, stream=True) r = requests.request(method=request.method, url=url, data=request.data, headers=r_headers, stream=True)
headers = dict(r.headers) headers = dict(r.headers)
try:
headers.pop('Transfer-Encoding')
except KeyError:
pass
if 'Content-length' in r.headers and int(r.headers['Content-length']) > size_limit: if 'Content-length' in r.headers and int(r.headers['Content-length']) > size_limit:
return redirect(u + request.url.replace(request.base_url, '', 1)) return redirect(u + request.url.replace(request.base_url, '', 1))

Loading…
Cancel
Save