|
|
|
@ -1,4 +1,8 @@
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace DiscordChatExporter.Core.Utils.Extensions;
|
|
|
|
|
|
|
|
|
@ -8,4 +12,13 @@ public static class HttpExtensions
|
|
|
|
|
headers.TryGetValues(name, out var values)
|
|
|
|
|
? string.Concat(values)
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
|
|
|
|
|
// This is extremely frail, but there's no other way
|
|
|
|
|
Regex
|
|
|
|
|
.Match(ex.Message, @": (\d+) \(")
|
|
|
|
|
.Groups[1]
|
|
|
|
|
.Value
|
|
|
|
|
.NullIfWhiteSpace()?
|
|
|
|
|
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
|
|
|
|
|
}
|