aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorSaptak S <saptak013@gmail.com>2021-04-12 03:17:22 +0530
committerSaptak S <saptak013@gmail.com>2021-04-12 22:57:11 +0530
commit729cf2ef86f9b1864705d95fc76dcb972a0ab835 (patch)
tree2e629f9ab080a24e6bd194f9445822c14c7ba980 /cli
parent81700ecaea18313656142c531664ff690f2b8adc (diff)
downloadonionshare-729cf2ef86f9b1864705d95fc76dcb972a0ab835.tar.gz
onionshare-729cf2ef86f9b1864705d95fc76dcb972a0ab835.zip
Fixes content-length for the range requests logic
Diffstat (limited to 'cli')
-rw-r--r--cli/onionshare_cli/web/share_mode.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/cli/onionshare_cli/web/share_mode.py b/cli/onionshare_cli/web/share_mode.py
index 0767992d..ad5825a2 100644
--- a/cli/onionshare_cli/web/share_mode.py
+++ b/cli/onionshare_cli/web/share_mode.py
@@ -186,15 +186,15 @@ class ShareModeWeb(SendBaseModeWeb):
use_gzip = self.should_use_gzip()
if use_gzip:
file_to_download = self.gzip_filename
- filesize = self.gzip_filesize
+ self.filesize = self.gzip_filesize
etag = self.gzip_etag
else:
file_to_download = self.download_filename
- filesize = self.download_filesize
+ self.filesize = self.download_filesize
etag = self.download_etag
# for range requests
- range_, status_code = self.get_range_and_status_code(filesize, etag, self.last_modified)
+ range_, status_code = self.get_range_and_status_code(self.filesize, etag, self.last_modified)
# Tell GUI the download started
history_id = self.cur_history_id
@@ -210,20 +210,22 @@ class ShareModeWeb(SendBaseModeWeb):
else:
r = Response(
self.generate(shutdown_func, range_, file_to_download, request_path,
- history_id, filesize))
+ history_id, self.filesize))
if use_gzip:
r.headers.set('Content-Encoding', 'gzip')
- r.headers.set('Content-Length', range_[1] - range_[0])
- r.headers.set('Content-Disposition', 'attachment', filename=basename)
+ r.headers.set('Content-Length', range_[1] - range_[0] + 1)
+ filename_dict = {
+ "filename": unidecode(basename),
+ "filename*": "UTF-8''%s" % url_quote(basename),
+ }
+ r.headers.set('Content-Disposition', 'attachment', **filename_dict)
r = self.web.add_security_headers(r)
# guess content type
(content_type, _) = mimetypes.guess_type(basename, strict=False)
if content_type is not None:
r.headers.set('Content-Type', content_type)
-
- r.headers.set('Content-Length', range_[1] - range_[0])
r.headers.set('Accept-Ranges', 'bytes')
r.headers.set('ETag', etag)
r.headers.set('Last-Modified', http_date(self.last_modified))
@@ -232,7 +234,7 @@ class ShareModeWeb(SendBaseModeWeb):
if status_code == 206:
r.headers.set('Content-Range',
- 'bytes {}-{}/{}'.format(range_[0], range_[1], filesize))
+ 'bytes {}-{}/{}'.format(range_[0], range_[1], self.filesize))
r.status_code = status_code