mirror of https://github.com/hunshcn/gh-proxy
修复python版本无法clone的问题
parent
0ad9808763
commit
f292a385a6
|
@ -29,7 +29,7 @@ def index():
|
||||||
return index_html
|
return index_html
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<path:u>')
|
@app.route('/<path:u>', methods=['GET', 'POST'])
|
||||||
def proxy(u):
|
def proxy(u):
|
||||||
u = u if u.startswith('http') else 'https://' + u
|
u = u if u.startswith('http') else 'https://' + u
|
||||||
u = u.replace(':/g', '://g', 1) # uwsgi会将//传递为/
|
u = u.replace(':/g', '://g', 1) # uwsgi会将//传递为/
|
||||||
|
@ -50,12 +50,16 @@ 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 + request.url.replace(request.base_url, ''), headers=r_headers, stream=True)
|
r = requests.request(method=request.method, url=u + request.url.replace(request.base_url, ''), data=request.data, 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)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
headers = dict(r.headers)
|
headers = dict(r.headers)
|
||||||
|
try:
|
||||||
|
headers.pop('Transfer-Encoding')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
for chunk in r.iter_content(chunk_size=CHUNK_SIZE):
|
for chunk in r.iter_content(chunk_size=CHUNK_SIZE):
|
||||||
|
|
Loading…
Reference in New Issue