Skip to content

Commit

Permalink
Fix handle empty content-disposition headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Aug 8, 2017
1 parent 42596b9 commit 11969d7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions headless/tasks/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def download_file(url, direct_access=False, user=None, password=None):
f.write(chunk)

# get extension
content_disposition = r.headers['content-disposition']
fname = re.findall("filename=[\'\"]?(.+)[\'\"]", content_disposition)
_, ext = os.path.splitext(fname[0])
shutil.move(tmpfile, '%s%s' % (tmpfile, ext))
tmpfile = '%s%s' % (tmpfile, ext)
# Headers is a CaseInsensitive keys. check content-disposition
if 'content-disposition' in r.headers:
content_disposition = r.headers['content-disposition']
fname = re.findall("filename=[\'\"]?(.+)[\'\"]", content_disposition)
_, ext = os.path.splitext(fname[0])
shutil.move(tmpfile, '%s%s' % (tmpfile, ext))
tmpfile = '%s%s' % (tmpfile, ext)
return tmpfile
elif parsed_uri.scheme == 'file':
file_path = urllib.unquote_plus(parsed_uri.path).decode('utf-8')
Expand Down

0 comments on commit 11969d7

Please sign in to comment.