Fixed buggy gopher support

This commit is contained in:
aewens 2018-10-04 11:32:19 -04:00
parent b3fd8fdbc0
commit 81bf0a5cca
1 changed files with 12 additions and 6 deletions

View File

@ -135,6 +135,12 @@ def shorten(url):
if len(url) > app.config["MAX_URL_LENGTH"]:
abort(414)
# handler to convert gopher links to HTTP(S) proxy
gopher = "gopher://"
length = len(gopher)
if url[:length] == gopher:
url = "https://gopher.tilde.team/{}".format(url[length:])
if not url_valid(url) or is_fhost_url(url) or "\n" in url:
abort(400)
@ -233,14 +239,14 @@ def store_file(f, addr):
return sf.geturl()
def store_url(url, addr):
if is_fhost_url(url):
return segfault(508)
# handler to convert gopher links to HTTP(S) proxy
gopher = "gopher://"
if url[:len(gopher)] = gopher:
address = url.split(gopher, 1)[1]
url = "https://gopher.tilde.team/{}".format(address)
length = len(gopher)
if url[:length] == gopher:
url = "https://gopher.tilde.team/{}".format(url[length:])
if is_fhost_url(url):
return segfault(508)
h = { "Accept-Encoding" : "identity" }
r = requests.get(url, stream=True, verify=False, headers=h)