Skip to content

Commit

Permalink
Merge pull request #283 from tmenier/dev
Browse files Browse the repository at this point in the history
Flurl.Http 2.2.1
  • Loading branch information
tmenier authored Mar 8, 2018
2 parents 5972682 + b3a7660 commit 79d6b3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Flurl.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flurl", "src\Flurl\Flurl.csproj", "{117B6C6E-53F9-45AE-9439-F4FB7E21B116}"
EndProject
Expand Down
12 changes: 11 additions & 1 deletion Test/Flurl.Test/Http/SettingsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ public void can_set_header() {

[Test]
public void can_set_headers_from_anon_object() {
var sc = GetSettingsContainer().WithHeaders(new { a = "b", one = 2 });
// null values shouldn't be added
var sc = GetSettingsContainer().WithHeaders(new { a = "b", one = 2, three = (object)null });
Assert.AreEqual(2, sc.Headers.Count);
Assert.AreEqual("b", sc.Headers["a"]);
Assert.AreEqual(2, sc.Headers["one"]);
}

[Test]
public void can_remove_header_by_setting_null() {
var sc = GetSettingsContainer().WithHeaders(new { a = 1, b = 2 });
Assert.AreEqual(2, sc.Headers.Count);
sc.WithHeader("b", null);
Assert.AreEqual(1, sc.Headers.Count);
Assert.AreEqual("a", sc.Headers.Keys.Single());
}

[Test]
public void can_set_headers_from_dictionary() {
var sc = GetSettingsContainer().WithHeaders(new Dictionary<string, object> { { "a", "b" }, { "one", 2 } });
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl.Http/Flurl.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;netstandard1.1;netstandard1.3;netstandard2.0;</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl.Http</PackageId>
<Version>2.2.0</Version>
<Version>2.2.1</Version>
<Authors>Todd Menier</Authors>
<Description>A fluent, portable, testable HTTP client library.</Description>
<PackageProjectUrl>http://tmenier.github.io/Flurl</PackageProjectUrl>
Expand Down
5 changes: 4 additions & 1 deletion src/Flurl.Http/HeaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public static class HeaderExtensions
/// <param name="value">HTTP header value.</param>
/// <returns>This IFlurlClient or IFlurlRequest.</returns>
public static T WithHeader<T>(this T clientOrRequest, string name, object value) where T : IHttpSettingsContainer {
clientOrRequest.Headers[name] = value;
if (value == null && clientOrRequest.Headers.ContainsKey(name))
clientOrRequest.Headers.Remove(name);
else if (value != null)
clientOrRequest.Headers[name] = value;
return clientOrRequest;
}

Expand Down

0 comments on commit 79d6b3c

Please sign in to comment.