mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-10-29 19:40:00 -04:00
added http digest auth to download clients
This commit is contained in:
1 parent
9f44e0e33f
commit
c16a6753f4
37 files changed
+5376
-66
No files matched your search
+27
@@ -0,0 +1,27 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace Cleanuparr.Infrastructure.Http.DynamicHttpClientSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Sends Basic auth up front for qBittorrent, Deluge and SABnzbd behind a reverse proxy.
|
||||
/// Skips requests that already carry an Authorization header.
|
||||
/// </summary>
|
||||
public sealed class BasicAuthHttpMessageHandler : DelegatingHandler
|
||||
{
|
||||
private readonly string _headerValue;
|
||||
|
||||
public BasicAuthHttpMessageHandler(NetworkCredential credential)
|
||||
{
|
||||
string raw = $"{credential.UserName}:{credential.Password}";
|
||||
_headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(raw));
|
||||
}
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.Headers.Authorization ??= new AuthenticationHeaderValue("Basic", _headerValue);
|
||||
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user