Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed DaprEndpoint property as it should utilize that registered wi…
…th the DaprClient instance. If a developer wants to opt-out, they should use the static invocation method instead.

Updated unit tests to exclude invalid endpoints as that's handled by the DaprClient instead now.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
  • Loading branch information
WhitWaldo committed Jul 4, 2024
commit 14c2172c12c689eaa02b7aa96fa5780be6d6120a
5 changes: 2 additions & 3 deletions src/Dapr.Client/DaprClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public HttpRequestMessage CreateInvokeMethodRequest<TRequest>(string appId, stri
/// <para>
/// The client will read the <see cref="HttpRequestMessage.RequestUri" /> property, and
/// interpret the hostname as the destination <c>app-id</c>. The <see cref="HttpRequestMessage.RequestUri" />
/// property will be replaced with a new URI with the authority section replaced by <paramref name="daprEndpoint" />
/// property will be replaced with a new URI with the authority section replaced by the HTTP endpoint value
/// and the path portion of the URI rewritten to follow the format of a Dapr service invocation request.
/// </para>
/// </summary>
Expand All @@ -466,11 +466,10 @@ public HttpRequestMessage CreateInvokeMethodRequest<TRequest>(string appId, stri
/// <see cref="HttpClient.BaseAddress" /> so that relative URIs can be used. It is mandatory to set this parameter if your app-id contains at least one upper letter.
/// If some requests use absolute URL with an app-id which contains at least one upper letter, it will not work, the workaround is to create one HttpClient for each app-id with the app-ip parameter set.
/// </param>
/// <param name="daprEndpoint">The HTTP endpoint of the Dapr process to use for service invocation calls.</param>
/// <returns>An <see cref="HttpClient" /> that can be used to perform service invocation requests.</returns>
/// <remarks>
/// </remarks>
public abstract HttpClient CreateInvokableHttpClient(string? appId = null, string? daprEndpoint = null);
public abstract HttpClient CreateInvokableHttpClient(string? appId = null);
#nullable disable

/// <summary>
Expand Down
9 changes: 4 additions & 5 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public override async Task<HttpResponseMessage> InvokeMethodWithResponseAsync(Ht
/// <para>
/// The client will read the <see cref="HttpRequestMessage.RequestUri" /> property, and
/// interpret the hostname as the destination <c>app-id</c>. The <see cref="HttpRequestMessage.RequestUri" />
/// property will be replaced with a new URI with the authority section replaced by <paramref name="daprEndpoint" />
/// property will be replaced with a new URI with the authority section replaced by the instance's <see cref="httpEndpoint"/> value
/// and the path portion of the URI rewritten to follow the format of a Dapr service invocation request.
/// </para>
/// </summary>
Expand All @@ -467,12 +467,11 @@ public override async Task<HttpResponseMessage> InvokeMethodWithResponseAsync(Ht
/// <see cref="HttpClient.BaseAddress" /> so that relative URIs can be used. It is mandatory to set this parameter if your app-id contains at least one upper letter.
/// If some requests use absolute URL with an app-id which contains at least one upper letter, it will not work, the workaround is to create one HttpClient for each app-id with the app-ip parameter set.
/// </param>
/// <param name="daprEndpoint"></param>
/// <returns>An <see cref="HttpClient" /> that can be used to perform service invocation requests.</returns>
/// <remarks>
/// </remarks>
#nullable enable
public override HttpClient CreateInvokableHttpClient(string? appId = null, string? daprEndpoint = null)
public override HttpClient CreateInvokableHttpClient(string? appId = null)
{
var handler = new InvocationHandler
Comment thread
WhitWaldo marked this conversation as resolved.
Outdated
{
Expand All @@ -486,10 +485,10 @@ public override HttpClient CreateInvokableHttpClient(string? appId = null, strin
handler.DaprApiToken = this.apiTokenHeader.Value.Value;
}

if (daprEndpoint is not null)
if (this.httpEndpoint is not null)
{
//DaprEndpoint performs validation
handler.DaprEndpoint = daprEndpoint;
handler.DaprEndpoint = this.httpEndpoint.AbsoluteUri;
}

var httpClient = new HttpClient(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class DaprClientTest
public void CreateInvokableHttpClient_WithAppId_FromDaprClient()
{
var daprClient = new MockClient().DaprClient;
var client = daprClient.CreateInvokableHttpClient(appId: "bank", daprEndpoint: "http://localhost:3500");
var client = daprClient.CreateInvokableHttpClient(appId: "bank");
Assert.Equal("http://bank/", client.BaseAddress.AbsoluteUri);
}

Expand All @@ -44,32 +44,9 @@ public void CreateInvokableHttpClient_InvalidAppId_FromDaprClient()
public void CreateInvokableHttpClient_WithoutAppId_FromDaprClient()
{
var daprClient = new MockClient().DaprClient;
var client = daprClient.CreateInvokableHttpClient(daprEndpoint: "http://localhost:3500");

var client = daprClient.CreateInvokableHttpClient();
Assert.Null(client.BaseAddress);
}

[Fact]
public void CreateInvokableHttpClient_InvalidDaprEndpoint_InvalidFormat_FromDaprClient()
{
var daprClient = new MockClient().DaprClient;
Assert.Throws<UriFormatException>(() =>
{
_ = daprClient.CreateInvokableHttpClient(daprEndpoint: "");
});

// Exception message comes from the runtime, not validating it here.
}

[Fact]
public void CreateInvokableHttpClient_InvalidDaprEndpoint_InvalidScheme_FromDaprClient()
{
var daprClient = new MockClient().DaprClient;
var ex = Assert.Throws<ArgumentException>(() =>
{
_ = daprClient.CreateInvokableHttpClient(daprEndpoint: "ftp://localhost:3500");
});

Assert.Contains("The URI scheme of the Dapr endpoint must be http or https.", ex.Message);
}
}
}