Skip to content

Commit 7a80649

Browse files
committed
add default User-Agent header when not set
1 parent fa8253e commit 7a80649

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/GraphQL.Client/GraphQLHttpClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Concurrent;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Net.Http;
7+
using System.Net.Http.Headers;
68
using System.Threading;
79
using System.Threading.Tasks;
810
using GraphQL.Client.Abstractions;
@@ -57,6 +59,10 @@ public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJson
5759
Options = options ?? throw new ArgumentNullException(nameof(options));
5860
JsonSerializer = serializer ?? throw new ArgumentNullException(nameof(serializer), "please configure the JSON serializer you want to use");
5961
HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
62+
63+
if (!HttpClient.DefaultRequestHeaders.UserAgent.Any())
64+
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version.ToString()));
65+
6066
_graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this);
6167
}
6268

0 commit comments

Comments
 (0)