diff --git a/notes/nugets.txt b/notes/nugets.txt index 4e07ccb..419422c 100644 --- a/notes/nugets.txt +++ b/notes/nugets.txt @@ -9,5 +9,5 @@ dotnet nuget push NetworkResurrector.Server.Wrapper.1.0.3.3.nupkg -k ***REMOVED* # Agent dotnet nuget push NetworkResurrector.Agent.PublishedLanguage.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget -dotnet nuget push NetworkResurrector.Agent.Wrapper.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget +dotnet nuget push NetworkResurrector.Agent.Wrapper.1.0.3.1.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget ####################################################################################################################################################### \ No newline at end of file diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs b/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs index 67b0809..9f5365b 100644 --- a/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs +++ b/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs @@ -1,12 +1,16 @@ using Microsoft.Extensions.DependencyInjection; +using NetworkResurrector.Agent.Wrapper.Models; using NetworkResurrector.Agent.Wrapper.Services; +using NetworkResurrector.Agent.Wrapper.Services.Internal; namespace NetworkResurrector.Agent.Wrapper { public static class DependencyInjectionExtension { - public static void UseResurrectorAgentServices(this IServiceCollection services) + public static void UseResurrectorAgentServices(this IServiceCollection services, bool forwardHeaders = true) { + services.AddSingleton(new ServiceConfiguration(forwardHeaders)); + services.AddScoped(); services.AddHttpClient(); } } diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Models/ServiceConfiguration.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Models/ServiceConfiguration.cs new file mode 100644 index 0000000..950068f --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Models/ServiceConfiguration.cs @@ -0,0 +1,12 @@ +namespace NetworkResurrector.Agent.Wrapper.Models +{ + internal class ServiceConfiguration + { + public bool ForwardHeaders { get; } + + public ServiceConfiguration(bool forwardHeaders) + { + ForwardHeaders = forwardHeaders; + } + } +} diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj b/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj index e71e673..6422dc6 100644 --- a/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj +++ b/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj @@ -6,11 +6,14 @@ https://dev.azure.com/tstanciu94/NetworkResurrector Git https://dev.azure.com/tstanciu94/NetworkResurrector + 1.0.3.1 + + diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Services/Internal/HttpHeadersService.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Services/Internal/HttpHeadersService.cs new file mode 100644 index 0000000..ae77ca5 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/Internal/HttpHeadersService.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Primitives; +using Microsoft.Net.Http.Headers; +using System.Net.Http; + +namespace NetworkResurrector.Agent.Wrapper.Services.Internal +{ + internal class HttpHeadersService + { + private readonly string[] _headersToForward = new string[] { HeaderNames.Authorization }; + private readonly IHttpContextAccessor _httpAccessor; + + public HttpHeadersService(IHttpContextAccessor httpAccessor) + { + _httpAccessor=httpAccessor; + } + + public void SetHeadersFromContext(HttpClient httpClient) + { + foreach (var headerKey in _headersToForward) + { + var header = _httpAccessor.HttpContext.Request.Headers[headerKey]; + if (header == StringValues.Empty) + continue; + + httpClient.DefaultRequestHeaders.Add(headerKey, header.ToString()); + } + } + } +} diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs index d00eb4e..09a5c47 100644 --- a/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs @@ -3,6 +3,8 @@ using NetworkResurrector.Agent.PublishedLanguage.Commands; using NetworkResurrector.Agent.PublishedLanguage.Dto; using NetworkResurrector.Agent.PublishedLanguage.Events; using NetworkResurrector.Agent.Wrapper.Constants; +using NetworkResurrector.Agent.Wrapper.Models; +using NetworkResurrector.Agent.Wrapper.Services.Internal; using System; using System.Net.Http; using System.Net.Http.Headers; @@ -15,10 +17,15 @@ namespace NetworkResurrector.Agent.Wrapper.Services private const string _contentType = "application/json"; private readonly HttpClient _httpClient; - public ResurrectorAgentService(HttpClient httpClient) + public ResurrectorAgentService(HttpClient httpClient, ServiceConfiguration configuration, HttpHeadersService headersService) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType)); + if (configuration.ForwardHeaders) + { + headersService.SetHeadersFromContext(httpClient); + } + _httpClient = httpClient; } diff --git a/src/api/NetworkResurrector.Api/Startup.cs b/src/api/NetworkResurrector.Api/Startup.cs index bc7edbe..b4e0455 100644 --- a/src/api/NetworkResurrector.Api/Startup.cs +++ b/src/api/NetworkResurrector.Api/Startup.cs @@ -1,11 +1,9 @@ -using AutoMapper; using MediatR; using MediatR.Pipeline; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using NDB.Extensions.Swagger; using NDB.Extensions.Swagger.Constants; using NDB.Security.Authentication.Identity; diff --git a/src/server/NetworkResurrector.Server.Wrapper/Services/Internal/HttpHeadersService.cs b/src/server/NetworkResurrector.Server.Wrapper/Services/Internal/HttpHeadersService.cs index 731deed..87ca1b4 100644 --- a/src/server/NetworkResurrector.Server.Wrapper/Services/Internal/HttpHeadersService.cs +++ b/src/server/NetworkResurrector.Server.Wrapper/Services/Internal/HttpHeadersService.cs @@ -7,7 +7,7 @@ namespace NetworkResurrector.Server.Wrapper.Services.Internal { internal class HttpHeadersService { - private readonly string[] _headersToForward = new string[] { HeaderNames.Authorization, "rr" }; + private readonly string[] _headersToForward = new string[] { HeaderNames.Authorization }; private readonly IHttpContextAccessor _httpAccessor; public HttpHeadersService(IHttpContextAccessor httpAccessor)