Move code from IRelativeHttpClient to IHttpClient.
MODIFY
WalletWasabi/Tor/Http/IHttpClient.cs
WalletWasabi/Tor/Http/IHttpClient.cs
using System;
using System.Net.Http;
-using System.Security.Authentication;
using System.Threading;
using System.Threading.Tasks;
namespace WalletWasabi.Tor.Http
{
/// <summary>
- /// Interface defining HTTP client capable of sending HTTP requests.
+ /// Interface defining HTTP client capable of sending either absolute or relative HTTP requests.
/// </summary>
+ /// <remarks>Relative HTTP requests are allowed only when <see cref="DestinationUriAction"/> returns non-<see langword="null"/> value.</remarks>
public interface IHttpClient
{
+ Func<Uri?> DestinationUriAction { get; }
+
+ /// <summary>
+ /// Whether each HTTP(s) request should use a separate Tor circuit by default or not to increase privacy.
+ /// <para>This property may be set to <c>false</c> and you can still call override the value when sending a single HTTP(s) request using <see cref="IHttpClient"/> API.</para>
+ /// </summary>
+ /// <remarks>The property name make sense only when talking about Tor <see cref="TorHttpClient"/>.</remarks>
+ bool DefaultIsolateStream { get; }
+
/// <summary>Sends an HTTP(s) request.</summary>
/// <param name="request">HTTP request message to send.</param>
/// <param name="isolateStream"><c>true</c> value is only available for Tor HTTP client to use a new Tor circuit
@@ -18,5 +27,31 @@ namespace WalletWasabi.Tor.Http
/// implementation does not support this option (e.g. clearnet).</param>
/// <param name="token">Cancellation token to cancel the asynchronous operation.</param>
Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool isolateStream, CancellationToken token = default);
+
+ Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
+ {
+ return SendAsync(request, DefaultIsolateStream, token);
+ }
+
+ /// <exception cref="InvalidOperationException"/>
+ async Task<HttpResponseMessage> SendAsync(HttpMethod method, string relativeUri, HttpContent? content = null, CancellationToken cancel = default)
+ {
+ Uri? baseUri = DestinationUriAction.Invoke();
+
+ if (baseUri is null)
+ {
+ throw new InvalidOperationException("Base URI is not set.");
+ }
+
+ var requestUri = new Uri(baseUri, relativeUri);
+ using var httpRequestMessage = new HttpRequestMessage(method, requestUri);
+
+ if (content is { })
+ {
+ httpRequestMessage.Content = content;
+ }
+
+ return await SendAsync(httpRequestMessage, DefaultIsolateStream, cancel).ConfigureAwait(false);
+ }
}
}
\ No newline at end of file

DELETE
WalletWasabi/Tor/Http/IRelativeHttpClient.cs
-using System;
-using System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace WalletWasabi.Tor.Http
-{
- /// <summary>
- /// Interface defining HTTP client capable of sending HTTP requests that are relative to some base URI.
- /// <para>This is useful, for example, to send requests to Wasabi Backend server.</para>
- /// </summary>
- public interface IRelativeHttpClient : IHttpClient
- {
- Func<Uri> DestinationUriAction { get; }
-
- /// <summary>
- /// Whether each HTTP(s) request should use a separate Tor circuit by default or not to increase privacy.
- /// <para>This property may be set to <c>false</c> and you can still call override the value when sending a single HTTP(s) request using <see cref="IHttpClient"/> API.</para>
- /// </summary>
- /// <remarks>The property name make sense only when talking about Tor <see cref="TorHttpClient"/>.</remarks>
- bool DefaultIsolateStream { get; }
-
- Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token = default)
- {
- return SendAsync(request, DefaultIsolateStream, token);
- }
-
- async Task<HttpResponseMessage> SendAsync(HttpMethod method, string relativeUri, HttpContent? content = null, CancellationToken cancel = default)
- {
- var requestUri = new Uri(DestinationUriAction.Invoke(), relativeUri);
- using var httpRequestMessage = new HttpRequestMessage(method, requestUri);
-
- if (content is { })
- {
- httpRequestMessage.Content = content;
- }
-
- return await SendAsync(httpRequestMessage, DefaultIsolateStream, cancel).ConfigureAwait(false);
- }
- }
-}

Move code from IRelativeHttpClient to IHttpClient.

Signed-off-by: Kiminuo <kiminuo@protonmail.com>