From f7432cc8db8b8f835f7699a15be762932688ed9a Mon Sep 17 00:00:00 2001 From: Mauricio Gomes Date: Wed, 11 Nov 2020 23:37:03 -0500 Subject: [PATCH] Fix filename calculation when header is missing --- fetch.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fetch.go b/fetch.go index 2d7b81f..5523dff 100644 --- a/fetch.go +++ b/fetch.go @@ -59,14 +59,14 @@ func fetchMetadata(uri string) (filesize uint64, filename string, err error) { contentDisposition := resp.Header.Get("Content-Disposition") _, params, err := mime.ParseMediaType(contentDisposition) if err != nil { - return filesize, "", nil + filename = filenameFromURI(uri) + return filesize, filename, nil } filename = params["filename"] // No filename specified in the header; use the pathname if filename == "" { - splitUri := strings.Split(uri, "/") - filename = splitUri[len(splitUri)-1] + filename = filenameFromURI(uri) } return @@ -142,6 +142,11 @@ func downloadPartFilename(part int) string { return fmt.Sprintf("download.part%d", part) } +func filenameFromURI(uri string) string { + splitUri := strings.Split(uri, "/") + return splitUri[len(splitUri)-1] +} + func concatFiles(filename string, parts int) { var readers []io.Reader