Allow HttpRequestMessage to accept relative URLs in service invocation
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
## Background
The Dapr SDK allows invoking service methods using an `HttpRequestMessage` parameter. However, this overload requires a fully qualified URL to the Dapr sidecar. Otherwise, an `InvalidOperationException` is thrown.
```csharp
HttpRequestMessage httpRequest = new(input.HttpMethod, input.MethodName);
return await this.daprClient.InvokeMethodAsync(httpRequest);
```
Here is the exception:
```
System.InvalidOperationException
HResult=0x80131509
Message=An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
Source=System.Net.Http
StackTrace:
at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
at System.Net.Http.HttpClient.CheckRequestBeforeSend(HttpRequestMessage request)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Dapr.Client.DaprClientGrpc.d__27.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dapr.Client.DaprClientGrpc.d__29`1.MoveNext()
...
[Call Stack Truncated]
```
Generally speaking, code that already has a fully configured `DaprClient` should not need to provide redundant endpoint information for the Dapr sidecar. In many cases, it may not be practical for code to know what it is - for example, when getting the `DaprClient` from dependency injection, in which case the configuration comes from the config system.
## Proposal
Remove the requirement in `InvokeMethodAsync` for the `HttpRequestMessage` parameter to use a fully qualified URL. The `DaprClient` implementation can construct the real URL itself using its own internally tracked endpoint. This will make this particular method much easier to use.
Contributor guide
Assessment
This issue has not been assessed yet.