diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-06 11:54:35 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-06 11:54:35 +0100 |
commit | 0474671ea11c0e78471dff1c830d8dd74d08f8cb (patch) | |
tree | 7d4f6c2cb209fa50bcd753de4b882adb32ce6113 | |
parent | 0ced254dc02070f9db943746fa55268003475383 (diff) |
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.
-rwxr-xr-x | fshare.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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') |