Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on http status codes >=300 for cURL downloads #2879

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,37 +243,37 @@ public static string DownloadText(Uri url, string authToken = "")

return agent.DownloadString(url.OriginalString);
}
catch (Exception)
catch (Exception e)
{
try
{
log.InfoFormat("Download failed, trying with curlsharp...");
log.InfoFormat(e.ToString());
log.InfoFormat("Download failed, trying with curlsharp...");

var content = string.Empty;
var content = string.Empty;

var client = Curl.CreateEasy(url.OriginalString, delegate (byte[] buf, int size, int nmemb, object extraData)
{
content += Encoding.UTF8.GetString(buf);
return size * nmemb;
});
var client = Curl.CreateEasy(url.OriginalString, delegate (byte[] buf, int size, int nmemb, object extraData)
{
content += Encoding.UTF8.GetString(buf);
return size * nmemb;
});

using (client)
{
var result = client.Perform();
client.SetOpt(CurlOption.FailOnError, true);

using (client)
{
var result = client.Perform();
var returnCode = client.ResponseCode;

if (result != CurlCode.Ok)
{
throw new Exception("Curl download failed with error " + result);
}
if (result != CurlCode.Ok)
{
throw new WebException(
String.Format("Curl download failed with error {0} ({1})", result, returnCode),
e
);
}

log.DebugFormat("Download from {0}:\r\n\r\n{1}", url, content);
log.DebugFormat("Download from {0}:\r\n\r\n{1}", url, content);

return content;
}
}
catch (Exception e)
{
throw new Kraken("Downloading using cURL failed", e);
return content;
}
}
}
Expand Down