Skip to content

Commit

Permalink
add workaround for FileZilla downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
striezel committed Jul 10, 2024
1 parent b91f677 commit 9d86028
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ __[new features]__

* Update support for MariaDB 11.4 is added.

__[changes]__

* Add workaround for failing downloads of FileZilla Client.

__[maintenance]__

* Update certificate information for Firefox ESR installers.
Expand Down
6 changes: 5 additions & 1 deletion updater/operations/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private static string Download(string url, bool showProgress)
}
}
string localFile = Path.Combine(cacheDirectory, basename);
using (WebClient wc = showProgress ? new ProgressReportingWebClient() : new WebClient())
using (WebClient wc = showProgress ? new ProgressReportingWebClient() : new AutoDecompressWebClient())
{
var lowerCaseUrl = url.ToLowerInvariant();
if (lowerCaseUrl.Contains("filezilla") || lowerCaseUrl.Contains("mariadb"))
Expand All @@ -416,6 +416,10 @@ private static string Download(string url, bool showProgress)
// (Yes, I am pointing at you, FileZilla download server!)
// Let's pretend we are Firefox ESR downloading the file.
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0");
if (lowerCaseUrl.Contains("filezilla"))
{
wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
}
}
if (lowerCaseUrl.Contains("irfanview"))
{
Expand Down
51 changes: 51 additions & 0 deletions updater/utility/AutoDecompressWebClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This file is part of the updater command line interface.
Copyright (C) 2024 Dirk Stolle
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Net;

namespace updater.utility
{
/// <summary>
/// WebClient that automatically adds automatic decompression.
/// </summary>
public class AutoDecompressWebClient : WebClient
{
/// <summary>
/// Initializes a new instance of ProgressReportingWebClient.
/// </summary>
public AutoDecompressWebClient() : base()
{
}


protected override WebRequest GetWebRequest(Uri address)
{
if (address.OriginalString.ToLowerInvariant().Contains("filezilla"))
{
var req = base.GetWebRequest(address) as HttpWebRequest;
req.AutomaticDecompression = DecompressionMethods.All;
return req;
}
else
{
return base.GetWebRequest(address);
}
}
}
}
8 changes: 8 additions & 0 deletions updater/utility/ProgressReportingWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public ProgressReportingWebClient() : base()
}


protected override WebRequest GetWebRequest(Uri address)
{
var req = base.GetWebRequest(address) as HttpWebRequest;
req.AutomaticDecompression = DecompressionMethods.All;
return req;
}


/// <summary>
/// Time when the current request started.
/// Should be set manually before the start of each request / download,
Expand Down

0 comments on commit 9d86028

Please sign in to comment.