/
afanasevn
/
RedisLab
Обзор
Документация
Войти
/
afanasevn
/
RedisLab
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/RedisLab.IntegrationTests/Support/HttpClientExtensions.cs
45 строк
1 KB
IBS\NAfanasev
Solution commit
24 июн 2026, 16:45
24 июн 2026, 16:45
bab80b7
Код
Авторство
О чём код?
using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; namespace RedisLab.IntegrationTests.Support; internal static class HttpClientExtensions { private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true, }; internal static async Task<string> LoginAsync( this HttpClient client, string email, string password, string? forwardedFor = null) { using var request = new HttpRequestMessage(HttpMethod.Post, "/api/auth/login") { Content = JsonContent.Create(new { email, password }), }; if (forwardedFor is not null) { request.Headers.Add("X-Forwarded-For", forwardedFor); } var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); var body = await response.Content.ReadFromJsonAsync<LoginResponsePayload>(JsonOptions); return body!.Token; } internal static void SetBearerToken( this HttpClient client, string token) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); } private sealed record LoginResponsePayload(string Token); }