From 5f491cee02c39350cc0130b5c1ee6a97767a08fb Mon Sep 17 00:00:00 2001 From: ant1k9 Date: Wed, 17 Nov 2021 22:52:46 +0700 Subject: [PATCH] Fall back to filename from URL when don't have it in the header In case we have a valid header, we'll try to get unsafeName from it but we cannot do it: > content-disposition: attachment So, we fall back to a default case, getting the filename right from the URL and fix it, if we have a filename in the content-disposition. --- .gitignore | 2 ++ download.go | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e2ed0b7..1984fed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ dist/ coverage.out +*.dat +*.output diff --git a/download.go b/download.go index f0b500e..89565ae 100644 --- a/download.go +++ b/download.go @@ -333,12 +333,13 @@ func (d *Download) Path() string { // Set the default path if d.path == "" { + d.path = GetFilename(d.URL) // default case if d.Dest != "" { d.path = d.Dest } else if d.unsafeName != "" { - d.path = getNameFromHeader(d.unsafeName) - } else { - d.path = GetFilename(d.URL) + if path := getNameFromHeader(d.unsafeName); path != "" { + d.path = path + } } d.path = filepath.Join(d.Dir, d.path) }