From 69cd5a834ef725438a99d70f19d909cce531a4d4 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Tue, 23 Apr 2024 10:30:39 -0700 Subject: [PATCH] chore: fix duplicate header bug --- server/StrDss.Service/EmailMessageService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/StrDss.Service/EmailMessageService.cs b/server/StrDss.Service/EmailMessageService.cs index d80e30ab..93041659 100644 --- a/server/StrDss.Service/EmailMessageService.cs +++ b/server/StrDss.Service/EmailMessageService.cs @@ -53,7 +53,15 @@ public async Task SendEmailAsync(EmailContent emailContent) var token = await _chesTokenApi.GetTokenAsync(); var chesUrl = _config.GetValue("CHES_URL") ?? ""; - _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token!.AccessToken}"); + if (_httpClient.DefaultRequestHeaders.Contains("Authorization")) + { + _httpClient.DefaultRequestHeaders.Remove("Authorization"); + _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token!.AccessToken}"); + } + else + { + _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token!.AccessToken}"); + } var jsonContent = emailContent.ToString(); var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");