aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-05 21:11:56 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-05 21:11:56 +0100
commit0ced254dc02070f9db943746fa55268003475383 (patch)
tree4b3b1729e8bd136e75962d27fd0d8a17307844d2
parent2964234e15d06da95429451e7a9e6f7a4dfa8d0f (diff)
Preserve POSTed file extensions, if provided.
-rwxr-xr-xfshare.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/fshare.py b/fshare.py
index 188f62f..a6fed24 100755
--- a/fshare.py
+++ b/fshare.py
@@ -171,6 +171,9 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler):
def do_POST(self):
self._log_request()
+ src_fname = self._process_path(self.path)
+ ext = os.path.splitext(src_fname)[1]
+
if 'Transfer-Encoding' in self.headers:
if self.headers['Transfer-Encoding'] != 'chunked':
return self.send_error(HTTPStatus.NOT_IMPLEMENTED,
@@ -202,10 +205,10 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler):
os.close(temp_fd)
- fname = h.hexdigest()
- self._logger.info('Received file: %s', fname)
+ dst_fname = h.hexdigest() + ext
+ self._logger.info('Received file: %s', dst_fname)
- outpath = '/'.join((self.server.data_dir, fname))
+ outpath = '/'.join((self.server.data_dir, dst_fname))
if os.path.exists(outpath):
retcode = HTTPStatus.OK
os.remove(temp_path)
@@ -221,7 +224,7 @@ class FShareRequestHandler(hs.BaseHTTPRequestHandler):
except KeyError:
host = 'host.missing'
- reply = ('https://%s/%s' % (host, fname)).encode('ascii')
+ reply = ('https://%s/%s' % (host, dst_fname)).encode('ascii')
self.send_response(retcode)
self.send_header('Content-Type', 'text/plain')