Skip to content

Commit

Permalink
Now checking application name parse with a dummy http request to corr…
Browse files Browse the repository at this point in the history
…ectly catch all valid/invalid names
  • Loading branch information
NaluTripician committed Sep 16, 2022
1 parent 5951129 commit 655d47f
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,40 @@ public string ApplicationName
get => this.applicationName;
set
{
try
{
NameValueHeaderValue.Parse(value);
}
catch (FormatException fme)
{
throw new ArgumentException($"Application Name '{value}' is invalid.", fme);
}
Console.WriteLine(value);

//HttpWebRequest dummyRequest = (HttpWebRequest)WebRequest.Create("https://microsoft.com");
//dummyRequest.Headers.Add("useragent", "cosmos-netstandard-sdk");
//dummyRequest.Headers.Add("ApplicationName", value);
//Console.WriteLine(dummyRequest);

//HttpRequestMessage dummyMessage = new HttpRequestMessage(HttpMethod.Head, "https://microsoft.com");
//dummyMessage.Headers.Add("ApplicationName", value);
//Console.WriteLine(dummyMessage);

//HttpClient dummyHttpClient = new HttpClient
//{
// BaseAddress = new Uri("https://microsoft.com")
//};
//dummyHttpClient.AddUserAgentHeader(new UserAgentContainer(2, value));
//Console.WriteLine(dummyHttpClient);

HttpRequestMessage dummyMessage = new HttpRequestMessage(HttpMethod.Head, "https://microsoft.com");
dummyMessage.Headers.Add("User-Agent", value);

this.applicationName = value;
//NameValueHeaderValue.Parse(value);

Console.WriteLine();

//try
//{
// NameValueHeaderValue.Parse(value);
//}
//catch (FormatException fme)
//{
// throw new ArgumentException($"Application Name '{value}' is invalid.", fme);
//}

this.applicationName = value;
}
Expand Down

0 comments on commit 655d47f

Please sign in to comment.