Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 497bacf

Browse files
daletskyif2prateek
authored andcommitted
Fix for User-Agent header duplication on each http request (#83)
* Fix for User-Agent header duplication on each http request * Cleanup * Removing changes that will go into other PRs
1 parent 023b604 commit 497bacf

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

Analytics/Request/BlockingRequestHandler.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics;
33
using System.Net;
44
#if NET35
@@ -107,6 +107,15 @@ internal BlockingRequestHandler(Client client, TimeSpan timeout)
107107
#if NET35
108108
#else
109109
_httpClient = new HttpClient(handler) { Timeout = Timeout };
110+
#endif
111+
// Send user agent in the form of {library_name}/{library_version} as per RFC 7231.
112+
var context = new Context();
113+
var library = context["library"] as Dict;
114+
string szUserAgent = string.Format("{0}/{1}", library["name"], library["version"]);
115+
#if NET35
116+
_httpClient.Headers.Add("User-Agent", szUserAgent);
117+
#else
118+
_httpClient.DefaultRequestHeaders.Add("User-Agent", szUserAgent);
110119
#endif
111120
}
112121

@@ -132,16 +141,6 @@ public async Task MakeRequest(Batch batch)
132141
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", BasicAuthHeader(batch.WriteKey, string.Empty));
133142
#endif
134143

135-
// Send user agent in the form of {library_name}/{library_version} as per RFC 7231.
136-
var context = new Context();
137-
var library = context["library"] as Dict;
138-
string szUserAgent = string.Format("{0}/{1}", library["name"], library["version"]);
139-
#if NET35
140-
_httpClient.Headers.Add("User-Agent", szUserAgent);
141-
#else
142-
_httpClient.DefaultRequestHeaders.Add("User-Agent", szUserAgent);
143-
#endif
144-
145144
// Prepare request data;
146145
var requestData = Encoding.UTF8.GetBytes(json);
147146

Test.Net45/Test.Net45.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<Prefer32Bit>false</Prefer32Bit>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
40-
<HintPath>..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath>
39+
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
40+
<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
4141
</Reference>
4242
<Reference Include="System" />
4343
<Reference Include="System.Core" />

0 commit comments

Comments
 (0)