mirror of https://github.com/hunshcn/gh-proxy
增加raw.githubusercontent.com支持,修复clone直接走服务器流量时出现的问题
parent
4a3fe663f4
commit
d3768b71d9
14
app/main.py
14
app/main.py
|
@ -16,9 +16,10 @@ app = Flask(__name__)
|
||||||
app.debug = True
|
app.debug = True
|
||||||
CHUNK_SIZE = 1024 * 10
|
CHUNK_SIZE = 1024 * 10
|
||||||
index_html = requests.get(ASSET_URL, timeout=10).text
|
index_html = requests.get(ASSET_URL, timeout=10).text
|
||||||
exp1 = re.compile(r'^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$')
|
exp1 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:releases|archive)/.*$')
|
||||||
exp2 = re.compile(r'^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob)\/.*$')
|
exp2 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:blob)/.*$')
|
||||||
exp3 = re.compile(r'^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-upload-pack).*$')
|
exp3 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:info|git-upload-pack).*$')
|
||||||
|
exp4 = re.compile(r'^(?:https?://)?raw\.githubusercontent\.com/.+?/.+?/.+?/.+$')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
@ -38,7 +39,10 @@ def proxy(u):
|
||||||
elif cnpmjs and exp3.match(u):
|
elif cnpmjs and exp3.match(u):
|
||||||
u = u.replace('github.com', 'github.com.cnpmjs.org') + request.url.replace(request.base_url, '')
|
u = u.replace('github.com', 'github.com.cnpmjs.org') + request.url.replace(request.base_url, '')
|
||||||
return redirect(u)
|
return redirect(u)
|
||||||
# elif exp1.match(u):
|
elif jsdelivr and exp4.match(u):
|
||||||
|
u = re.sub(r'\.com/.*?/.+?/(.+?/)', '@$1', u, 1)
|
||||||
|
u = u.replace('raw.githubusercontent.com', 'cdn.jsdelivr.net/gh')
|
||||||
|
return redirect(u)
|
||||||
else:
|
else:
|
||||||
headers = {}
|
headers = {}
|
||||||
r_headers = {}
|
r_headers = {}
|
||||||
|
@ -46,7 +50,7 @@ def proxy(u):
|
||||||
if i in request.headers:
|
if i in request.headers:
|
||||||
r_headers[i] = request.headers.get(i)
|
r_headers[i] = request.headers.get(i)
|
||||||
try:
|
try:
|
||||||
r = requests.get(u, headers=r_headers, stream=True)
|
r = requests.get(u + request.url.replace(request.base_url, ''), headers=r_headers, stream=True)
|
||||||
for i in ['Content-Type']:
|
for i in ['Content-Type']:
|
||||||
if i in r.headers:
|
if i in r.headers:
|
||||||
headers[i] = r.headers.get(i)
|
headers[i] = r.headers.get(i)
|
||||||
|
|
Loading…
Reference in New Issue