Skip to content

Commit 67b673b

Browse files
committed
3.0.0 refactor http handler to minimal api endpoint
1 parent a9bea32 commit 67b673b

26 files changed

Lines changed: 338 additions & 464 deletions

NpgsqlRest/Auth/BasicAuthHandler.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static async Task HandleAsync(
4343
{
4444
logger?.LogWarning("No Authorization header found in request with Basic Authentication Realm {realm}. Request: {Path}",
4545
realm,
46-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
46+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
4747
await Challenge(context, realm);
4848
return;
4949
}
@@ -53,7 +53,7 @@ public static async Task HandleAsync(
5353
{
5454
logger?.LogWarning("Authorization header value missing or malformed found in request with Basic Authentication Realm {realm}. Request: {Path}",
5555
realm,
56-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
56+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
5757
await Challenge(context, realm);
5858
return;
5959
}
@@ -68,7 +68,7 @@ public static async Task HandleAsync(
6868
{
6969
logger?.LogError(ex, "Failed to decode Basic Authentication credentials in request with Basic Authentication Realm {realm}. Request: {Path}",
7070
realm,
71-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
71+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
7272
await Challenge(context, realm);
7373
return;
7474
}
@@ -78,7 +78,7 @@ public static async Task HandleAsync(
7878
{
7979
logger?.LogWarning("Authorization header value malformed found in request with Basic Authentication Realm {realm}. Request: {Path}",
8080
realm,
81-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
81+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
8282
await Challenge(context, realm);
8383
return;
8484
}
@@ -89,7 +89,7 @@ public static async Task HandleAsync(
8989
{
9090
logger?.LogWarning("Username or password missing in request with Basic Authentication Realm {realm}. Request: {Path}",
9191
realm,
92-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
92+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
9393
await Challenge(context, realm);
9494
return;
9595
}
@@ -115,7 +115,7 @@ public static async Task HandleAsync(
115115
{
116116
logger?.LogError("PasswordHasher not configured for Basic Authentication Realm {realm}. Request: {Path}",
117117
realm,
118-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
118+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
119119
await Challenge(context, realm);
120120
return;
121121
}
@@ -135,7 +135,7 @@ public static async Task HandleAsync(
135135
logger?.LogError("No Basic Authentication user configured for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}",
136136
username,
137137
realm,
138-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
138+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
139139
await Challenge(context, realm);
140140
return;
141141
}
@@ -168,7 +168,7 @@ public static async Task HandleAsync(
168168
}
169169
if (paramCount >= 5)
170170
{
171-
command.Parameters.Add(NpgsqlRestParameter.CreateTextParam(endpoint.Url));
171+
command.Parameters.Add(NpgsqlRestParameter.CreateTextParam(endpoint.Path));
172172
}
173173

174174
await LoginHandler.HandleAsync(
@@ -177,7 +177,7 @@ await LoginHandler.HandleAsync(
177177
options,
178178
endpoint.RetryStrategy,
179179
logger,
180-
tracePath: string.Concat(endpoint.Method.ToString(), " ", endpoint.Url),
180+
tracePath: string.Concat(endpoint.Method.ToString(), " ", endpoint.Path),
181181
performHashVerification: false,
182182
assignUserPrincipalToContext: true);
183183

@@ -189,7 +189,7 @@ await LoginHandler.HandleAsync(
189189
logger?.LogError("ChallengeCommand denied user {username} in request with Basic Authentication Realm {realm}. Request: {Path}",
190190
username,
191191
realm,
192-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
192+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
193193
await Challenge(context, realm);
194194
return;
195195
}
@@ -210,7 +210,7 @@ await LoginHandler.HandleAsync(
210210
logger?.LogWarning("Invalid password for user {username} in request with Basic Authentication Realm {realm}. Request: {Path}",
211211
username,
212212
realm,
213-
string.Concat(endpoint.Method.ToString(), endpoint.Url));
213+
string.Concat(endpoint.Method.ToString(), endpoint.Path));
214214
await Challenge(context, realm);
215215
}
216216
}

NpgsqlRest/Auth/LogoutHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class LogoutHandler
1313
{
1414
public static async Task HandleAsync(NpgsqlCommand command, RoutineEndpoint endpoint, HttpContext context, ILogger? logger)
1515
{
16-
var path = string.Concat(endpoint.Method.ToString(), " ", endpoint.Url);
16+
var path = string.Concat(endpoint.Method.ToString(), " ", endpoint.Path);
1717
logger?.TraceCommand(command, path);
1818

1919
if (endpoint.Routine.IsVoid)

NpgsqlRest/Defaults/DefaultCommentParser.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ internal static class DefaultCommentParser
218218
return routineEndpoint;
219219
}
220220

221-
var originalUrl = routineEndpoint.Url;
221+
var originalUrl = routineEndpoint.Path;
222222
var originalMethod = routineEndpoint.Method;
223223
var originalParamType = routineEndpoint.RequestParamType;
224224

@@ -236,7 +236,7 @@ internal static class DefaultCommentParser
236236
{
237237

238238
var routineDescription = string.Concat(routine.Type, " ", routine.Schema, ".", routine.Name);
239-
var urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Url);
239+
var urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Path);
240240
var description = string.Concat(routineDescription, " mapped to ", urlDescription);
241241

242242
string[] lines = comment.Split(NewlineSeparator, StringSplitOptions.RemoveEmptyEntries);
@@ -414,24 +414,24 @@ internal static class DefaultCommentParser
414414
{
415415
if (!Uri.TryCreate(urlPathSegment, UriKind.Relative, out Uri? uri))
416416
{
417-
logger?.InvalidUrlPathSegmentComment(urlPathSegment, description, routineEndpoint.Url);
417+
logger?.InvalidUrlPathSegmentComment(urlPathSegment, description, routineEndpoint.Path);
418418
}
419419
else
420420
{
421-
routineEndpoint.Url = uri.ToString();
422-
if (!routineEndpoint.Url.StartsWith('/'))
421+
routineEndpoint.Path = uri.ToString();
422+
if (!routineEndpoint.Path.StartsWith('/'))
423423
{
424-
routineEndpoint.Url = string.Concat("/", routineEndpoint.Url);
424+
routineEndpoint.Path = string.Concat("/", routineEndpoint.Path);
425425
}
426426
}
427427
}
428-
if (routineEndpoint.Method != originalMethod || !string.Equals(routineEndpoint.Url, originalUrl))
428+
if (routineEndpoint.Method != originalMethod || !string.Equals(routineEndpoint.Path, originalUrl))
429429
{
430430
if (options.LogAnnotationSetInfo)
431431
{
432-
logger?.CommentSetHttp(description, routineEndpoint.Method, routineEndpoint.Url);
432+
logger?.CommentSetHttp(description, routineEndpoint.Method, routineEndpoint.Path);
433433
}
434-
urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Url);
434+
urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Path);
435435
description = string.Concat(routineDescription, " mapped to ", urlDescription);
436436
}
437437
}
@@ -444,21 +444,21 @@ internal static class DefaultCommentParser
444444
string? urlPathSegment = wordsLower[1];
445445
if (!Uri.TryCreate(urlPathSegment, UriKind.Relative, out Uri? uri))
446446
{
447-
logger?.InvalidUrlPathSegmentComment(urlPathSegment, description, routineEndpoint.Url);
447+
logger?.InvalidUrlPathSegmentComment(urlPathSegment, description, routineEndpoint.Path);
448448
}
449449
else
450450
{
451-
routineEndpoint.Url = uri.ToString();
452-
if (!routineEndpoint.Url.StartsWith('/'))
451+
routineEndpoint.Path = uri.ToString();
452+
if (!routineEndpoint.Path.StartsWith('/'))
453453
{
454-
routineEndpoint.Url = string.Concat("/", routineEndpoint.Url);
454+
routineEndpoint.Path = string.Concat("/", routineEndpoint.Path);
455455
}
456456

457457
if (options.LogAnnotationSetInfo)
458458
{
459-
logger?.CommentSetHttp(description, routineEndpoint.Method, routineEndpoint.Url);
459+
logger?.CommentSetHttp(description, routineEndpoint.Method, routineEndpoint.Path);
460460
}
461-
urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Url);
461+
urlDescription = string.Concat(routineEndpoint.Method.ToString(), " ", routineEndpoint.Path);
462462
description = string.Concat(routineDescription, " mapped to ", urlDescription);
463463
}
464464
}

NpgsqlRest/Defaults/DefaultEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static class DefaultEndpoint
2727

2828
RoutineEndpoint routineEndpoint = new(
2929
routine,
30-
url: url,
30+
path: url,
3131
method: method,
3232
requestParamType: requestParamType,
3333
requiresAuthorization: options.RequiresAuthorization,

NpgsqlRest/NpgsqlRest.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
<GenerateDocumentationFile>true</GenerateDocumentationFile>
3030
<PackageReadmeFile>README.MD</PackageReadmeFile>
3131
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
32-
<Version>2.37.0</Version>
33-
<AssemblyVersion>2.37.0</AssemblyVersion>
34-
<FileVersion>2.37.0</FileVersion>
35-
<PackageVersion>2.37.0</PackageVersion>
32+
<Version>3.0.0</Version>
33+
<AssemblyVersion>3.0.0</AssemblyVersion>
34+
<FileVersion>3.0.0</FileVersion>
35+
<PackageVersion>3.0.0</PackageVersion>
36+
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
3637
</PropertyGroup>
3738

3839
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

0 commit comments

Comments
 (0)