mirror of https://github.com/hunshcn/gh-proxy
fix: monkey patch for default headers
parent
f309780131
commit
2410b99e3d
|
@ -7,7 +7,7 @@ from requests.exceptions import (
|
||||||
ChunkedEncodingError,
|
ChunkedEncodingError,
|
||||||
ContentDecodingError, ConnectionError, StreamConsumedError)
|
ContentDecodingError, ConnectionError, StreamConsumedError)
|
||||||
from requests.utils import (
|
from requests.utils import (
|
||||||
stream_decode_response_unicode, iter_slices)
|
stream_decode_response_unicode, iter_slices, CaseInsensitiveDict)
|
||||||
from urllib3.exceptions import (
|
from urllib3.exceptions import (
|
||||||
DecodeError, ReadTimeoutError, ProtocolError)
|
DecodeError, ReadTimeoutError, ProtocolError)
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ exp3 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:info|git-).*$')
|
||||||
exp4 = re.compile(r'^(?:https?://)?raw\.githubusercontent\.com/.+?/.+?/.+?/.+$')
|
exp4 = re.compile(r'^(?:https?://)?raw\.githubusercontent\.com/.+?/.+?/.+?/.+$')
|
||||||
exp5 = re.compile(r'^(?:https?://)?gist\.(?:githubusercontent|github)\.com/.+?/.+?/.+$')
|
exp5 = re.compile(r'^(?:https?://)?gist\.(?:githubusercontent|github)\.com/.+?/.+?/.+$')
|
||||||
|
|
||||||
|
requests.sessions.default_headers = lambda: CaseInsensitiveDict()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
@ -108,7 +110,6 @@ def proxy(u):
|
||||||
r_headers = dict(request.headers)
|
r_headers = dict(request.headers)
|
||||||
if 'Host' in r_headers:
|
if 'Host' in r_headers:
|
||||||
r_headers.pop('Host')
|
r_headers.pop('Host')
|
||||||
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://'):
|
||||||
|
|
Loading…
Reference in New Issue