mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-22 01:42:08 +10:00
Refactor: reorganise namespaces and move service DTOs to Models/Contracts
- Move Client/Http, Services, Parsers under Infrastructure/ (Client, Services, Parsers) - Move config helpers (DnsmasqConfKeys, DnsmasqOptionTooltips, DnsmasqFileEncoding, EffectiveConfigFieldBuilder) to Infrastructure/Helpers/Config; ApiJsonOptions to Helpers/Http - Move Configuration types (ApplicationOptions, DnsmasqOptions, DnsmasqOptionsValidator) to Models/Config - Merge Models/Status and Models/EffectiveConfig into Models/Dnsmasq and Models/Dnsmasq/EffectiveConfig - Move Client/Models and Client/Services to Models/Client and Infrastructure/Services - Move ConfigSetSnapshot, HostsSnapshot, ProcessRunResult, ManagedConfigContent from Infrastructure/Services/Abstractions to Models/Contracts - Update all namespaces and usings; tests pass
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System.Net;
|
||||
using DnsmasqWebUI.Infrastructure.Services.Abstractions;
|
||||
|
||||
namespace DnsmasqWebUI.Infrastructure.Client;
|
||||
|
||||
/// <summary>
|
||||
/// DelegatingHandler that rewrites relative request URIs to the current request's scheme, host, and path base.
|
||||
/// Used so Blazor/API callers can use relative paths (e.g. "/api/status") and hit the same host.
|
||||
/// Resolved in the same scope as the code that requested the HttpClient (e.g. Blazor component),
|
||||
/// so IHttpContextAccessor has the current request when available.
|
||||
/// </summary>
|
||||
public sealed class SameHostBaseAddressHandler(IHttpContextAccessor httpContextAccessor) : DelegatingHandler, IApplicationScopedConcrete
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var context = httpContextAccessor.HttpContext;
|
||||
if (context != null && request.RequestUri != null)
|
||||
{
|
||||
var baseUri = new Uri($"{context.Request.Scheme}://{context.Request.Host.Value}{context.Request.PathBase.Value ?? ""}");
|
||||
request.RequestUri = request.RequestUri.IsAbsoluteUri
|
||||
? new Uri(baseUri, request.RequestUri.PathAndQuery)
|
||||
: new Uri(baseUri, request.RequestUri);
|
||||
}
|
||||
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user