2
2
Fork 0

Add support for serving tilde URLs out of homedirs.

This commit is contained in:
Solderpunk 2019-10-26 15:02:12 +03:00
parent e7d0879bd5
commit 7aa87c903e
1 changed files with 12 additions and 1 deletions

View File

@ -41,7 +41,16 @@ class GegobiHandler(socketserver.BaseRequestHandler):
self.send_gemini_header(50, "This server does not proxy requests.")
return
# Resolve path to filesystem
local_path = os.path.join(self.server.args.base, urllib.parse.unquote(self.request_path))
if self.request_path.startswith("~") or self.request_path.startswith("/~") and self.server.args.tilde:
if self.request_path.startswith("/"):
self.request_path = self.request_path[1:]
bits = self.request_path.split(os.sep)
bits.insert(1, self.server.args.tilde)
bits.insert(0, os.sep + "home")
local_path = os.path.join(*bits)
else:
local_path = os.path.join(self.server.args.base, urllib.parse.unquote(self.request_path))
print(local_path)
# Handle not founds
if not os.path.exists(local_path):
self.send_gemini_header(51, "Not found.")
@ -249,6 +258,8 @@ Gemini protocol as well, resulting in "Gemini-Gopher bi-hosting"
help='Serve only on 127.0.0.1.')
parser.add_argument('--port', type=int, nargs="?", default=1965,
help='TCP port to serve on.')
parser.add_argument('--tilde', type=str, nargs="?", default="",
help='Home subdirectory to map tilde URLs to.')
args = parser.parse_args()
if not (os.path.exists(args.cert) and os.path.exists(args.key)):