From 0474671ea11c0e78471dff1c830d8dd74d08f8cb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 6 Jan 2021 11:54:35 +0100 Subject: Change extension handling. Store POSTed files as pure HMAC - without any extensions - but still keep the extension in the returned URL. Disregard the extension in GET requests, allowing to access the files with any extension. --- fshare.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fshare.py b/fshare.py index a6fed24..d5092b3 100755 --- a/fshare.py +++ b/fshare.py @@ -148,7 +148,8 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler): def do_GET(self): self._log_request() - fname = self._process_path(self.path) + # discard any extension + fname = os.path.splitext(self._process_path(self.path))[0] path = '/'.join((self.server.data_dir, fname)) self._logger.info('serve file: %s', fname) @@ -205,7 +206,7 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler): os.close(temp_fd) - dst_fname = h.hexdigest() + ext + dst_fname = h.hexdigest() self._logger.info('Received file: %s', dst_fname) outpath = '/'.join((self.server.data_dir, dst_fname)) @@ -224,7 +225,8 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler): except KeyError: host = 'host.missing' - reply = ('https://%s/%s' % (host, dst_fname)).encode('ascii') + path = urlparse.quote(dst_fname + ext) + reply = ('https://%s/%s' % (host, path)).encode('ascii') self.send_response(retcode) self.send_header('Content-Type', 'text/plain') -- cgit v1.2.3