2022-09-04 05:17:03 +00:00
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
2022-09-04 05:03:59 +00:00
|
|
|
namespace OrangeGuidanceTomestone.Helpers;
|
|
|
|
|
|
|
|
internal static class ServerHelper {
|
2023-01-22 00:03:43 +00:00
|
|
|
private static readonly HttpClient Client = new();
|
|
|
|
|
2022-09-08 03:13:55 +00:00
|
|
|
internal static HttpRequestMessage GetRequest(string? apiKey, HttpMethod method, string tail, string? contentType = null, HttpContent? content = null) {
|
2022-09-04 05:03:59 +00:00
|
|
|
if (!tail.StartsWith('/')) {
|
|
|
|
tail = '/' + tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = $"https://tryfingerbuthole.anna.lgbt{tail}";
|
|
|
|
var req = new HttpRequestMessage(method, url);
|
|
|
|
if (content != null) {
|
|
|
|
req.Content = content;
|
2022-09-04 05:17:03 +00:00
|
|
|
|
|
|
|
if (contentType != null) {
|
|
|
|
req.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
|
|
|
}
|
2022-09-04 05:03:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 03:13:55 +00:00
|
|
|
if (apiKey != null) {
|
|
|
|
req.Headers.Add("X-Api-Key", apiKey);
|
|
|
|
}
|
2022-09-04 05:03:59 +00:00
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2022-09-08 03:13:55 +00:00
|
|
|
internal static async Task<HttpResponseMessage> SendRequest(string? apiKey, HttpMethod method, string tail, string? contentType = null, HttpContent? content = null) {
|
2022-09-04 05:03:59 +00:00
|
|
|
var req = GetRequest(apiKey, method, tail, contentType, content);
|
2023-01-22 00:03:43 +00:00
|
|
|
return await Client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
|
2022-09-04 05:03:59 +00:00
|
|
|
}
|
|
|
|
}
|