Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosClientOptions: Adds validation for ApplicationName #3455

Merged
merged 18 commits into from
Sep 19, 2022
Merged
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
43 changes: 9 additions & 34 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,15 @@ public string ApplicationName
get => this.applicationName;
set
{
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);
//}
try
{
HttpRequestMessage dummyMessage = new HttpRequestMessage(HttpMethod.Head, "https://microsoft.com");
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
dummyMessage.Headers.Add("User-Agent", value);
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
}
catch (FormatException fme)
{
throw new ArgumentException($"Application name '{value}' is invalid.", fme);
}

this.applicationName = value;
}
Expand Down