using System.Net.Http.Headers; using System.Text; namespace adas_core.module.Relays.Utils; /// /// Utility class for handling HTTP-related operations, such as adding basic authentication headers to HTTP requests. /// public static class HttpUtils { /// /// Adds basic authentication to the provided HttpRequestHeaders. /// /// The username for basic authentication. /// The password for basic authentication. /// The HttpRequestHeaders to which the authentication will be added. /// The HttpRequestHeaders with the added basic authentication. public static HttpRequestHeaders AddBasicAuth(string username, string password, HttpRequestHeaders headers) { var auth = Encoding.ASCII.GetBytes($"{username}:{password}"); var clientAuthorizationHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(auth)); headers.Add("Authorization", clientAuthorizationHeader.ToString()); return headers; } }