namespace OAuthClient;

public class OriginHandler : DelegatingHandler {
    private readonly string _origin;

    public OriginHandler(string origin) {
        _origin = origin;
        InnerHandler = new HttpClientHandler();
    }

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
        CancellationToken cancellationToken) {
        // Add the Origin header to the request
        if (!request.Headers.Contains("Origin")) {
            request.Headers.Add("Origin", _origin);
        }

        return base.SendAsync(request, cancellationToken);
    }
}