File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ public RestClient(
210
210
static void ConfigureHttpClient ( HttpClient httpClient , RestClientOptions options ) {
211
211
if ( options . MaxTimeout > 0 ) httpClient . Timeout = TimeSpan . FromMilliseconds ( options . MaxTimeout ) ;
212
212
213
- if ( options . UserAgent != null && httpClient . DefaultRequestHeaders . UserAgent . All ( x => x . Product ? . Name != options . UserAgent ) ) {
213
+ if ( options . UserAgent != null && httpClient . DefaultRequestHeaders . UserAgent . All ( x => $ " { x . Product ? . Name } / { x . Product ? . Version } " != Options . UserAgent ) ) {
214
214
httpClient . DefaultRequestHeaders . TryAddWithoutValidation ( KnownHeaders . UserAgent , options . UserAgent ) ;
215
215
}
216
216
Original file line number Diff line number Diff line change @@ -116,4 +116,19 @@ public void Should_use_new_httpClient_instance() {
116
116
117
117
client1 . HttpClient . Should ( ) . NotBeSameAs ( client2 . HttpClient ) ;
118
118
}
119
+
120
+ [ Fact ]
121
+ public void ConfigureHttpClient_does_not_duplicate_user_agent_for_same_client ( ) {
122
+ // arrange
123
+ var httpClient = new HttpClient ( ) ;
124
+ var clientOptions = new RestClientOptions ( ) ;
125
+
126
+ // act
127
+ var restClient1 = new RestClient ( httpClient , clientOptions ) ;
128
+ var restClient2 = new RestClient ( httpClient , clientOptions ) ;
129
+
130
+ // assert
131
+ Assert . Contains ( httpClient . DefaultRequestHeaders . UserAgent , agent => $ "{ agent . Product . Name } /{ agent . Product . Version } " == clientOptions . UserAgent ) ;
132
+ Assert . Single ( httpClient . DefaultRequestHeaders . UserAgent ) ;
133
+ }
119
134
}
You can’t perform that action at this time.
0 commit comments