Skip to content

Commit

Permalink
Careless is a h3h3 fanboy :)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiilikewiki committed Dec 16, 2021
1 parent 8986f5a commit 781275e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@ public static int GetEpoch(this DateTime span) {
double t = (span - new DateTime(1970, 1, 1)).TotalSeconds;
return (int) t;
}

public static bool CheckSuccess(this HttpResponseMessage msg) {
try {
msg.EnsureSuccessStatusCode();
}
catch {
return false;
}
return true;
}
}
}
8 changes: 4 additions & 4 deletions SophosSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class SophosSession
private int _goodRequests;
private int _failedRequests;

public int TotalSessionRequests { get => _goodRequests + _failedRequests; }


public SophosSession(SophosSessionConfiguration config) {
_username = System.Web.HttpUtility.UrlEncode(config.Username);
Expand Down Expand Up @@ -63,7 +65,6 @@ public async Task Login() {
throw new WebException("Request failed: " + msg.StatusCode);
}


_client.DefaultRequestHeaders.Remove("X-Requested-With");

}
Expand All @@ -83,8 +84,7 @@ public async Task KeepAlive() {
ThreadPool.QueueUserWorkItem(async (o) => {
while (true) {
await Task.Delay(300000);
ConsoleLogger.LogInfo($"Sent {_goodRequests + _failedRequests} heartbeats in the past five minutes.");
ConsoleLogger.LogInfo($"{_goodRequests}/{_failedRequests + _goodRequests} succeeded");
ConsoleLogger.LogInfo($"Sent {TotalSessionRequests} heartbeats in the past five minutes. {_goodRequests}/{TotalSessionRequests} succeeded");
_goodRequests = 0;
_failedRequests = 0;
}
Expand All @@ -93,7 +93,7 @@ public async Task KeepAlive() {
while (true) {
await Task.Delay(_heartbeatTimeout);
msg = await _client.PostAsync(url, new FormUrlEncodedContent(new Dictionary<string, string>()));
if (msg.StatusCode != HttpStatusCode.OK)
if (!msg.CheckSuccess())
_failedRequests++;
else
_goodRequests++;
Expand Down

0 comments on commit 781275e

Please sign in to comment.