Skip to content

Commit cc909d7

Browse files
author
Nick Craver
committed
General cleanup
1 parent 301832b commit cc909d7

11 files changed

+25
-29
lines changed

.editorconfig

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ csharp_new_line_before_else = true
7777
csharp_new_line_before_catch = true
7878
csharp_new_line_before_finally = true
7979
csharp_new_line_before_members_in_object_initializers = true
80-
csharp_new_line_before_members_in_anonymous_types = true
80+
csharp_new_line_before_members_in_anonymous_types = true
81+
82+
# RCS1090: Call 'ConfigureAwait(false)'.
83+
dotnet_diagnostic.RCS1090.severity = silent

src/Directory.Build.props

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<Authors>Stack Exchange</Authors>
1313
<PackageId>$(AssemblyName)</PackageId>
1414
<Copyright>Stack Exchange, Inc. 2018</Copyright>
15-
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
15+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1616
<PackageProjectUrl>https://github.com/StackExchange/StackExchange.Utils</PackageProjectUrl>
1717
<RepositoryUrl>https://github.com/StackExchange/StackExchange.Utils</RepositoryUrl>
1818
<RepositoryType>git</RepositoryType>
1919
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Nerdbank.GitVersioning" Version="2.3.105" PrivateAssets="all" />
24-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All"/>
23+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.28" PrivateAssets="all" />
24+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
2525
</ItemGroup>
2626
</Project>

src/StackExchange.Utils.Http/DefaultHttpClientPool.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public bool Equals(HttpClientCacheKey other)
9090
public override int GetHashCode()
9191
{
9292
var hashCode = 647927907;
93-
hashCode = hashCode * -1521134295 + EqualityComparer<TimeSpan>.Default.GetHashCode(Timeout);
94-
hashCode = hashCode * -1521134295 + EqualityComparer<IWebProxy>.Default.GetHashCode(Proxy);
93+
hashCode = (hashCode * -1521134295) + EqualityComparer<TimeSpan>.Default.GetHashCode(Timeout);
94+
hashCode = (hashCode * -1521134295) + EqualityComparer<IWebProxy>.Default.GetHashCode(Proxy);
9595
return hashCode;
9696
}
9797

src/StackExchange.Utils.Http/Extensions.Expect.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public static IRequestBuilder<bool> ExpectHttpSuccess(this IRequestBuilder build
1818
builder.WithHandler(responseMessage => Task.FromResult(responseMessage.IsSuccessStatusCode));
1919

2020
/// <summary>
21-
/// Holds handlers for ExpectJson(T) calls, so we don't re-create them in the common "default Options" case.
22-
///
23-
/// Without this, we create a new Func for each ExpectJson call even
21+
/// <para>Holds handlers for ExpectJson(T) calls, so we don't re-create them in the common "default Options" case.</para>
22+
/// <para>Without this, we create a new Func for each ExpectJson call even</para>
2423
/// </summary>
2524
/// <typeparam name="T">The type being deserialized.</typeparam>
2625
private static class JsonHandler<T>

src/StackExchange.Utils.Http/Extensions.Modifier.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static IRequestBuilder WithoutLogging(this IRequestBuilder builder, IEnum
7878
}
7979

8080
private static readonly ConcurrentDictionary<HttpStatusCode, ImmutableHashSet<HttpStatusCode>> _ignoreCache = new ConcurrentDictionary<HttpStatusCode, ImmutableHashSet<HttpStatusCode>>();
81+
8182
/// <summary>
8283
/// Doesn't log an error when the response's HTTP status code is <paramref name="ignoredStatusCode"/>.
8384
/// </summary>
@@ -125,7 +126,7 @@ public static IRequestBuilder AddHeader(this IRequestBuilder builder, string nam
125126
}
126127
return builder;
127128
}
128-
129+
129130
/// <summary>
130131
/// Adds a single header without Validation against known Header types.
131132
/// (ideal if you have different interpretation to the spec for any known types)
@@ -141,7 +142,6 @@ public static IRequestBuilder AddHeaderWithoutValidation(this IRequestBuilder bu
141142
try
142143
{
143144
builder.Message.Headers.TryAddWithoutValidation(name, value);
144-
145145
}
146146
catch (Exception e)
147147
{

src/StackExchange.Utils.Http/Extensions.Send.cs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public static IRequestBuilder SendForm(this IRequestBuilder builder, NameValueCo
4141
public static IRequestBuilder SendHtml(this IRequestBuilder builder, string html) =>
4242
SendContent(builder, new StringContent(html, Encoding.UTF8, "text/html"));
4343

44-
4544
/// <summary>
4645
/// Adds JSON (Jil-serialized) content as the body for this request.
4746
/// </summary>

src/StackExchange.Utils.Http/Extensions.Verbs.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static Task<HttpCallResponse<T>> PostAsync<T>(this IRequestBuilder<T> bui
4545
/// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
4646
public static Task<HttpCallResponse<T>> PutAsync<T>(this IRequestBuilder<T> builder, CancellationToken cancellationToken = default) =>
4747
Http.SendAsync(builder, HttpMethod.Put, cancellationToken);
48-
48+
4949
/// <summary>
5050
/// Issue the request as a PATCH.
5151
/// </summary>

src/StackExchange.Utils.Http/Http.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,10 @@ internal static async Task<HttpCallResponse<T>> SendAsync<T>(IRequestBuilder<T>
8686
exception = ex;
8787
}
8888

89-
var result = default(HttpCallResponse<T>);
90-
if (response == null)
91-
{
92-
result = HttpCallResponse.Create<T>(request, exception);
93-
}
94-
else
95-
{
96-
result = HttpCallResponse.Create<T>(response, exception);
97-
}
89+
// Use the response if we have it - request if not
90+
var result = response != null
91+
? HttpCallResponse.Create<T>(response, exception)
92+
: HttpCallResponse.Create<T>(request, exception);
9893

9994
// Add caller member bits to the exception data regardless of where it's eventually logged.
10095
(builder.Inner as HttpBuilder)?.AddExceptionData(exception);

src/StackExchange.Utils.Http/HttpSettings.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ public class HttpSettings
5757
public TimeSpan DefaultTimeout { get; set; } = TimeSpan.FromSeconds(30);
5858

5959
/// <summary>
60-
/// The default Proxy to use when making requests.
61-
///
60+
/// <para>The default Proxy to use when making requests.</para>
61+
/// <para>
6262
/// This should create a new instance of a proxy when called,
6363
/// so that modifications don't affect the default (e.g.,
6464
/// changing Proxy.Credentials on a builder.Proxy should
6565
/// not affect the Proxy.Credentials used by default)
66+
/// </para>
6667
/// </summary>
6768
public Func<IWebProxy> DefaultProxyFactory { get; set; } = null;
6869

tests/StackExchange.Utils.Tests/HttpBinResponse.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33

44
namespace StackExchange.Utils.Tests
55
{
6+
[DataContract]
67
public class HttpBinResponse
78
{
89
[DataMember(Name = "args")]
9-
public Dictionary<string, string> args { get; set; }
10+
public Dictionary<string, string> Args { get; set; }
1011

1112
[DataMember(Name = "data")]
1213
public string Data { get; set; }
1314

1415
[DataMember(Name = "files")]
15-
public Dictionary<string, string> files { get; set; }
16+
public Dictionary<string, string> Files { get; set; }
1617

1718
[DataMember(Name = "form")]
1819
public Dictionary<string, string> Form { get; set; }

tests/StackExchange.Utils.Tests/HttpTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Net;
44
using System.Net.Http;
5-
using System.Net.Http.Headers;
65
using System.Threading.Tasks;
76
using Xunit;
87

@@ -25,7 +24,6 @@ public async Task BasicCreation()
2524
[Fact]
2625
public async Task BasicGet()
2726
{
28-
var guid = Guid.NewGuid().ToString();
2927
var result = await Http.Request("https://httpbin.org/get")
3028
.ExpectJson<HttpBinResponse>()
3129
.GetAsync();
@@ -124,7 +122,7 @@ public async Task Timeouts()
124122
Assert.Equal("https://httpbin.org/delay/10", err.Uri.ToString());
125123
Assert.Null(err.StatusCode);
126124
}
127-
125+
128126
[Fact]
129127
public async Task AddHeaderWithoutValidation()
130128
{

0 commit comments

Comments
 (0)