Skip to content

Commit 756189a

Browse files
Fix issues reported by Rider
1 parent a741cbf commit 756189a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+134
-212
lines changed

API/Content/IErrorMapper.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IErrorMapper<in T> where T : Exception
1717
/// <param name="handler">The handler which catched the exception</param>
1818
/// <param name="error">The actual exception to be mapped</param>
1919
/// <returns>
20-
/// A HTTP response to be sent or null, if the error should be handled as not found by the next error handler in
20+
/// An HTTP response to be sent or null, if the error should be handled as not found by the next error handler in
2121
/// the chain
2222
/// </returns>
2323
ValueTask<IResponse?> Map(IRequest request, IHandler handler, T error);
@@ -28,8 +28,9 @@ public interface IErrorMapper<in T> where T : Exception
2828
/// <param name="request">The currently handled request</param>
2929
/// <param name="handler">The inner handler of the error handling concern</param>
3030
/// <returns>
31-
/// A HTTP response to be sent or null, if the error should be handled as not found by the next error handler in
31+
/// An HTTP response to be sent or null, if the error should be handled as not found by the next error handler in
3232
/// the chain
3333
/// </returns>
3434
ValueTask<IResponse?> GetNotFound(IRequest request, IHandler handler);
35+
3536
}

API/Protocol/ContentType.cs

+1
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ public static FlexibleContentType Parse(string header)
656656
{
657657
return Get(contentType, span[(charsetIndex + 1)..].Trim().ToString());
658658
}
659+
659660
return Get(contentType);
660661
}
661662
return Get(header);

API/Protocol/IRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public interface IRequest : IDisposable
9797
string? UserAgent { get; }
9898

9999
/// <summary>
100-
/// The referrer which caused the invociation of this request, if any.
100+
/// The referrer which caused the invocation of this request, if any.
101101
/// </summary>
102102
string? Referer { get; }
103103

API/Protocol/ResponseStatus.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public readonly struct FlexibleResponseStatus
138138

139139
#region Mapping
140140

141-
private static readonly Dictionary<ResponseStatus, string> MAPPING = new()
141+
private static readonly Dictionary<ResponseStatus, string> Mapping = new()
142142
{
143143
{
144144
ResponseStatus.Accepted, "Accepted"
@@ -295,7 +295,7 @@ public readonly struct FlexibleResponseStatus
295295
}
296296
};
297297

298-
private static readonly Dictionary<int, ResponseStatus> CODE_MAPPING = MAPPING.Keys.ToDictionary(k => (int)k, k => k);
298+
private static readonly Dictionary<int, ResponseStatus> CodeMapping = Mapping.Keys.ToDictionary(k => (int)k, k => k);
299299

300300
#endregion
301301

@@ -306,7 +306,7 @@ public FlexibleResponseStatus(int status, string phrase)
306306
RawStatus = status;
307307
Phrase = phrase;
308308

309-
if (CODE_MAPPING.TryGetValue(status, out var known))
309+
if (CodeMapping.TryGetValue(status, out var known))
310310
{
311311
KnownStatus = known;
312312
}
@@ -321,7 +321,7 @@ public FlexibleResponseStatus(ResponseStatus status)
321321
KnownStatus = status;
322322

323323
RawStatus = (int)status;
324-
Phrase = MAPPING[status];
324+
Phrase = Mapping[status];
325325
}
326326

327327
#endregion

API/Routing/RoutingTarget.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// </remarks>
1010
public sealed class RoutingTarget
1111
{
12-
private static readonly List<WebPathPart> EMPTY_LIST = [];
12+
private static readonly List<WebPathPart> EmptyList = [];
1313

1414
private int _Index;
1515

@@ -74,7 +74,7 @@ public WebPath GetRemaining()
7474
{
7575
var remaining = Path.Parts.Count - _Index;
7676

77-
var resultList = remaining > 0 ? new List<WebPathPart>(remaining) : EMPTY_LIST;
77+
var resultList = remaining > 0 ? new List<WebPathPart>(remaining) : EmptyList;
7878

7979
for (var i = _Index; i < Path.Parts.Count; i++)
8080
{

Adapters/AspNetCore/Adapter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void Map(this WebApplication app, string path, IHandlerBuilder han
3333
/// <param name="handler">The handler to be registered</param>
3434
/// <param name="companion">An object that will be informed about handled requests and any error</param>
3535
public static void Map(this WebApplication app, string path, IHandler handler, IServerCompanion? companion = null)
36-
=> app.Map(path + "/{*any}", async (context) => await Bridge.MapAsync(context, handler, companion: companion, registeredPath: path));
36+
=> app.Map(path + "/{*any}", async context => await Bridge.MapAsync(context, handler, companion: companion, registeredPath: path));
3737

3838
/// <summary>
3939
/// Registers the given handler to respond to any request.
@@ -42,7 +42,7 @@ public static void Map(this WebApplication app, string path, IHandler handler, I
4242
/// <param name="handler">The handler to be registered</param>
4343
/// <param name="server">The server instance that would like to execute requests</param>
4444
public static void Run(this IApplicationBuilder app, IHandler handler, IServer server)
45-
=> app.Run(async (context) => await Bridge.MapAsync(context, handler, server));
45+
=> app.Run(async context => await Bridge.MapAsync(context, handler, server));
4646

4747
/// <summary>
4848
/// Enables default features on the given handler. This should be used on the

Adapters/AspNetCore/Server/EmptyEndpoints.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
namespace GenHTTP.Adapters.AspNetCore.Server;
44

5-
public class EmptyEndpoints : List<IEndPoint>, IEndPointCollection
6-
{
7-
8-
}
5+
public class EmptyEndpoints : List<IEndPoint>, IEndPointCollection;

Adapters/AspNetCore/Types/Request.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public IHeaderCollection Headers
7070
get { return _Headers ??= new Headers(Context); }
7171
}
7272

73-
public Stream? Content => Context.BodyReader.AsStream(true);
73+
public Stream Content => Context.BodyReader.AsStream(true);
7474

7575
public FlexibleContentType? ContentType => (Context.ContentType != null) ? new(Context.ContentType) : null;
7676

Engine/Internal/Infrastructure/Endpoints/SecureEndPoint.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ internal SecureEndPoint(IServer server, IPAddress? address, ushort port, Securit
3535
{
3636
EnabledSslProtocols = Options.Protocols,
3737
AllowRenegotiation = true,
38-
ApplicationProtocols = new List<SslApplicationProtocol>
39-
{
40-
SslApplicationProtocol.Http11
41-
},
38+
ApplicationProtocols = [ SslApplicationProtocol.Http11 ],
4239
EncryptionPolicy = EncryptionPolicy.RequireEncryption,
4340
ServerCertificateSelectionCallback = SelectCertificate,
4441
ClientCertificateRequired = Options.CertificateValidator?.RequireCertificate ?? false,

Engine/Internal/Protocol/ClientHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ private async ValueTask<ConnectionStatus> HandlePipe(PipeReader reader)
116116

117117
var parser = new RequestParser(Configuration);
118118

119-
RequestBuilder? request;
120-
121119
try
122120
{
121+
RequestBuilder? request;
122+
123123
while (Server.Running && (request = await parser.TryParseAsync(buffer)) is not null)
124124
{
125125
var status = await HandleRequest(request, !buffer.ReadRequired);

Engine/Kestrel/Hosting/KestrelEndpoints.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
namespace GenHTTP.Engine.Kestrel.Hosting;
44

5-
public sealed class KestrelEndpoints : List<IEndPoint>, IEndPointCollection
6-
{
7-
8-
}
5+
public sealed class KestrelEndpoints : List<IEndPoint>, IEndPointCollection;

Engine/Shared/Security/SimpleCertificateProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public SimpleCertificateProvider(X509Certificate2 certificate)
1717

1818
#region Get-/Setters
1919

20-
internal X509Certificate2 Certificate { get; }
20+
public X509Certificate2 Certificate { get; }
2121

2222
#endregion
2323

Engine/Shared/Types/PooledDictionary.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,7 @@ public class PooledDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IReadOn
1616

1717
#region Get-/Setters
1818

19-
private KeyValuePair<TKey, TValue>[] Entries
20-
{
21-
get
22-
{
23-
if (_Entries is null)
24-
{
25-
_Entries = Pool.Rent(Capacity);
26-
}
27-
28-
return _Entries!;
29-
}
30-
}
19+
private KeyValuePair<TKey, TValue>[] Entries => _Entries ??= Pool.Rent(Capacity);
3120

3221
private bool HasEntries => _Entries is not null;
3322

Engine/Shared/Types/Response.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void SetCookie(Cookie cookie)
4444

4545
public ulong? ContentLength { get; set; }
4646

47-
public bool Upgraded { get; set; }
47+
public bool Upgraded { get; init; }
4848

4949
public IResponseContent? Content { get; set; }
5050

Modules/ApiBrowsing/Common/BrowserHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public BrowserHandler(string resourceRoot, BrowserMetaData metaData)
4343
{
4444
if (!request.HasType(RequestMethod.Get, RequestMethod.Head))
4545
{
46-
throw new ProviderException(ResponseStatus.MethodNotAllowed, "Only GET requests are allowed by this handler", (b) => b.Header("Allow", "GET"));
46+
throw new ProviderException(ResponseStatus.MethodNotAllowed, "Only GET requests are allowed by this handler", b => b.Header("Allow", "GET"));
4747
}
4848

4949
if (request.Target.Ended)

Modules/Authentication/Multi/MultiAuthenticationConcernBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class MultiAuthenticationConcernBuilder : IConcernBuilder
1414
{
1515
#region Fields
1616

17-
private readonly List<IConcernBuilder> _delegatingConcernsBuilders = [];
17+
private readonly List<IConcernBuilder> _DelegatingConcernsBuilders = [];
1818

1919
#endregion
2020

@@ -24,7 +24,7 @@ private MultiAuthenticationConcernBuilder AddIfNotNull(IConcernBuilder concernBu
2424
{
2525
if (concernBuilder == null) return this;
2626

27-
_delegatingConcernsBuilders.Add(concernBuilder);
27+
_DelegatingConcernsBuilders.Add(concernBuilder);
2828
return this;
2929
}
3030

@@ -74,7 +74,7 @@ public MultiAuthenticationConcernBuilder Add(ClientCertificateAuthenticationBuil
7474
/// <returns></returns>
7575
public IConcern Build(IHandler content)
7676
{
77-
var delegatingConcerns = _delegatingConcernsBuilders.Select(x => x.Build(content)).ToArray();
77+
var delegatingConcerns = _DelegatingConcernsBuilders.Select(x => x.Build(content)).ToArray();
7878
if (delegatingConcerns.Length == 0) throw new BuilderMissingPropertyException("Concerns");
7979

8080
return new MultiAuthenticationConcern(

Modules/Authentication/Roles/RoleInterceptor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Configure(object attribute)
5151

5252
if (missing.Count > 0)
5353
{
54-
throw new ProviderException(ResponseStatus.Forbidden, $"User is not authorized to access this endpoint.");
54+
throw new ProviderException(ResponseStatus.Forbidden, "User is not authorized to access this endpoint.");
5555
}
5656
}
5757

Modules/Caching/Memory/StreamMemoryCache.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public async ValueTask<Stream[]> GetEntriesAsync(string key)
2626
{
2727
var entry = await _Cache.GetEntryAsync(key, variation);
2828

29-
if (entry != null)
30-
{
31-
return new MemoryStream(entry);
32-
}
33-
34-
return null;
29+
return (entry != null) ? new MemoryStream(entry) : null;
3530
}
3631

3732
public async ValueTask StoreAsync(string key, string variation, Stream? entry)

Modules/ClientCaching/Validation/CacheValidationHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public CacheValidationHandler(IHandler content)
3434

3535
if (request.HasType(SupportedMethods))
3636
{
37-
if (response is not null && response.Content is not null)
37+
if (response?.Content != null)
3838
{
3939
var eTag = await CalculateETag(response);
4040

Modules/Functional/Provider/InlineBuilder.cs

+12-41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GenHTTP.Api.Content;
22
using GenHTTP.Api.Infrastructure;
33
using GenHTTP.Api.Protocol;
4+
45
using GenHTTP.Modules.Conversion;
56
using GenHTTP.Modules.Conversion.Formatters;
67
using GenHTTP.Modules.Conversion.Serializers;
@@ -11,7 +12,7 @@ namespace GenHTTP.Modules.Functional.Provider;
1112

1213
public class InlineBuilder : IHandlerBuilder<InlineBuilder>
1314
{
14-
private static readonly HashSet<FlexibleRequestMethod> AllMethods = [..Enum.GetValues<RequestMethod>().Select(m => FlexibleRequestMethod.Get(m))];
15+
private static readonly HashSet<FlexibleRequestMethod> AllMethods = [..Enum.GetValues<RequestMethod>().Select(FlexibleRequestMethod.Get)];
1516

1617
private readonly List<IConcernBuilder> _Concerns = [];
1718

@@ -73,92 +74,62 @@ public InlineBuilder Formatters(IBuilder<FormatterRegistry> registry)
7374
/// Adds a route for a GET request to the root of the handler.
7475
/// </summary>
7576
/// <param name="function">The logic to be executed</param>
76-
public InlineBuilder Get(Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
77-
{
78-
FlexibleRequestMethod.Get(RequestMethod.Get)
79-
});
77+
public InlineBuilder Get(Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Get)]);
8078

8179
/// <summary>
8280
/// Adds a route for a GET request to the specified path.
8381
/// </summary>
8482
/// <param name="path">The path of the request to handle (e.g. "/my-method")</param>
8583
/// <param name="function">The logic to be executed</param>
86-
public InlineBuilder Get(string path, Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
87-
{
88-
FlexibleRequestMethod.Get(RequestMethod.Get)
89-
}, path);
84+
public InlineBuilder Get(string path, Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Get)], path);
9085

9186
/// <summary>
9287
/// Adds a route for a HEAD request to the root of the handler.
9388
/// </summary>
9489
/// <param name="function">The logic to be executed</param>
95-
public InlineBuilder Head(Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
96-
{
97-
FlexibleRequestMethod.Get(RequestMethod.Head)
98-
});
90+
public InlineBuilder Head(Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Head)]);
9991

10092
/// <summary>
10193
/// Adds a route for a HEAD request to the specified path.
10294
/// </summary>
10395
/// <param name="path">The path of the request to handle (e.g. "/my-method")</param>
104-
public InlineBuilder Head(string path, Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
105-
{
106-
FlexibleRequestMethod.Get(RequestMethod.Head)
107-
}, path);
96+
public InlineBuilder Head(string path, Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Head)], path);
10897

10998
/// <summary>
11099
/// Adds a route for a POST request to the root of the handler.
111100
/// </summary>
112101
/// <param name="function">The logic to be executed</param>
113-
public InlineBuilder Post(Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
114-
{
115-
FlexibleRequestMethod.Get(RequestMethod.Post)
116-
});
102+
public InlineBuilder Post(Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Post)]);
117103

118104
/// <summary>
119105
/// Adds a route for a POST request to the specified path.
120106
/// </summary>
121107
/// <param name="path">The path of the request to handle (e.g. "/my-method")</param>
122-
public InlineBuilder Post(string path, Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
123-
{
124-
FlexibleRequestMethod.Get(RequestMethod.Post)
125-
}, path);
108+
public InlineBuilder Post(string path, Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Post)], path);
126109

127110
/// <summary>
128111
/// Adds a route for a PUT request to the root of the handler.
129112
/// </summary>
130113
/// <param name="function">The logic to be executed</param>
131-
public InlineBuilder Put(Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
132-
{
133-
FlexibleRequestMethod.Get(RequestMethod.Put)
134-
});
114+
public InlineBuilder Put(Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Put)]);
135115

136116
/// <summary>
137117
/// Adds a route for a PUT request to the specified path.
138118
/// </summary>
139119
/// <param name="path">The path of the request to handle (e.g. "/my-method")</param>
140-
public InlineBuilder Put(string path, Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
141-
{
142-
FlexibleRequestMethod.Get(RequestMethod.Put)
143-
}, path);
120+
public InlineBuilder Put(string path, Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Put)], path);
144121

145122
/// <summary>
146123
/// Adds a route for a DELETE request to the root of the handler.
147124
/// </summary>
148125
/// <param name="function">The logic to be executed</param>
149-
public InlineBuilder Delete(Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
150-
{
151-
FlexibleRequestMethod.Get(RequestMethod.Delete)
152-
});
126+
public InlineBuilder Delete(Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Delete)]);
153127

154128
/// <summary>
155129
/// Adds a route for a DELETE request to the specified path.
156130
/// </summary>
157131
/// <param name="path">The path of the request to handle (e.g. "/my-method")</param>
158-
public InlineBuilder Delete(string path, Delegate function) => On(function, new HashSet<FlexibleRequestMethod>
159-
{
160-
FlexibleRequestMethod.Get(RequestMethod.Delete)
161-
}, path);
132+
public InlineBuilder Delete(string path, Delegate function) => On(function, [FlexibleRequestMethod.Get(RequestMethod.Delete)], path);
162133

163134
/// <summary>
164135
/// Executes the given function for the specified path and method.

0 commit comments

Comments
 (0)