Skip to content

Commit

Permalink
cmd/extract: handle mime parsing failure
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Mar 30, 2024
1 parent a1f4278 commit 804a982
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ func writeFile(vmd *cobra.Command, resp *http.Response, record *warc.Record) err

if resp.Header.Get("Content-Disposition") != "" {
_, params, err := mime.ParseMediaType(resp.Header.Get("Content-Disposition"))
if err != nil {
return err
}
if err == nil {
if params["filename"] != "" {
filename = params["filename"]
}
} else {
logrus.Debugf("failed to parse Content-Disposition header: %v", err)

if params["filename"] != "" {
filename = params["filename"]
if !strings.HasSuffix(filename, ".pdf") {
filename += ".pdf"
}
}
}

Expand Down

0 comments on commit 804a982

Please sign in to comment.