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

Fix for User-Agent header duplication on each http request #83

Merged
merged 3 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 10 additions & 11 deletions Analytics/Request/BlockingRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Net;
#if NET35
Expand Down Expand Up @@ -107,6 +107,15 @@ internal BlockingRequestHandler(Client client, TimeSpan timeout)
#if NET35
#else
_httpClient = new HttpClient(handler) { Timeout = Timeout };
#endif
// Send user agent in the form of {library_name}/{library_version} as per RFC 7231.
var context = new Context();
var library = context["library"] as Dict;
string szUserAgent = string.Format("{0}/{1}", library["name"], library["version"]);
#if NET35
_httpClient.Headers.Add("User-Agent", szUserAgent);
#else
_httpClient.DefaultRequestHeaders.Add("User-Agent", szUserAgent);
#endif
}

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

// Send user agent in the form of {library_name}/{library_version} as per RFC 7231.
var context = new Context();
var library = context["library"] as Dict;
string szUserAgent = string.Format("{0}/{1}", library["name"], library["version"]);
#if NET35
_httpClient.Headers.Add("User-Agent", szUserAgent);
#else
_httpClient.DefaultRequestHeaders.Add("User-Agent", szUserAgent);
#endif

// Prepare request data;
var requestData = Encoding.UTF8.GetBytes(json);

Expand Down
4 changes: 2 additions & 2 deletions Test.Net45/Test.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious - why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't build test project because version 3.8.1 was referenced in packages.config. Since the same version is used across all other test projects I just fixed the path here.

<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down