Skip to content

Commit

Permalink
Fall-back for wrongly formated content-disposition headers (#610)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Hug <[email protected]>
  • Loading branch information
Aeon512 and Florian Hug committed Mar 31, 2023
1 parent 7da937e commit 36b569c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent
CompareChecksum(_tempFile, _args.CheckSum);
}

// try to parse the content disposition header if it exists
ContentDisposition contentDisposition = null;
if (!string.IsNullOrWhiteSpace(_webClient.ResponseHeaders?["Content-Disposition"]))
try
{
if (!string.IsNullOrWhiteSpace(_webClient.ResponseHeaders?["Content-Disposition"]))
{
contentDisposition = new ContentDisposition(_webClient.ResponseHeaders["Content-Disposition"]);
}
}
catch (FormatException)
{
contentDisposition = new ContentDisposition(_webClient.ResponseHeaders["Content-Disposition"]);
// ignore content disposition header if it is wrongly formated
contentDisposition = null;
}

var fileName = string.IsNullOrEmpty(contentDisposition?.FileName)
Expand Down

0 comments on commit 36b569c

Please sign in to comment.