dapr / dapr/dotnet-sdk

DaprClient.CreateInvokeHttpClient - Throw exception if some uppercase letters in appId

Open
#1,224 2 comments 0 reactions 0 assignees View on GitHub
area/client/invoke
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
2d 1h
Merged PRs (30d)
6

Description

## Describe the proposal
"DaprClient.CreateInvokeHttpClient" method does not work (misbehavior) if the parameter "appId" contains at least one uppercase letter.
The "HttpClient" instance has the "BaseAddress" (which is a URI) built with the "appId" parameter but it is NO case-sensitive.

My proposal is to throw a "ArgumentException" if there is at least one uppercase inside the "appId" string, because it will not working and it will save some time to new users (as could be for me).

A bug has already be opened here #937

[Source file](https://github.com/dapr/dotnet-sdk/blob/master/src/Dapr.Client/DaprClient.cs)

The change will be this :
```

public static HttpClient CreateInvokeHttpClient(string appId = null, string daprEndpoint = null, string daprApiToken = null)
{
var handler = new InvocationHandler()
{
InnerHandler = new HttpClientHandler(),
DaprApiToken = daprApiToken
};

if (daprEndpoint is string)
{
// DaprEndpoint performs validation.
handler.DaprEndpoint = daprEndpoint;
}

var httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.UserAgent.Add(UserAgent());

if (appId is string)
{

if(appId.Any(char.IsUpper))
{
throw new ArgumentException("The appId cannot contain an uppercase letter.", nameof(appId));
}

try
{
httpClient.BaseAddress = new Uri($"http://{appId}");
}
catch (UriFormatException inner)
{
throw new ArgumentException("The appId must be a valid hostname.", nameof(appId), inner);
}
}

return httpClient;
}

If you agree, I will make a PR.
Thanks all.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.