Skip to content

Commit 8eb9603

Browse files
John Luopranavkm
andauthored
Api docs for Diagnostics middlewares (#26525)
* Api docs for Diagnostics middlewares * Update ExceptionHandlerFeature.cs * Update StatusCodePagesMiddleware.cs * Update ExceptionHandlerMiddleware.cs * Apply suggestions from code review Co-authored-by: Pranav K <[email protected]> Co-authored-by: Pranav K <[email protected]>
1 parent 6f6e192 commit 8eb9603

15 files changed

+130
-14
lines changed

src/Middleware/Diagnostics.Abstractions/src/DiagnosticMessage.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ namespace Microsoft.AspNetCore.Diagnostics
88
/// </summary>
99
public class DiagnosticMessage
1010
{
11+
/// <summary>
12+
/// Initializes a new instance of <see cref="DiagnosticMessage"/>.
13+
/// </summary>
14+
/// <param name="message">The error message.</param>
15+
/// <param name="formattedMessage">The formatted error message.</param>
16+
/// <param name="filePath">The path of the file that produced the message.</param>
17+
/// <param name="startLine">The one-based line index for the start of the compilation error.</param>
18+
/// <param name="startColumn">The zero-based column index for the start of the compilation error.</param>
19+
/// <param name="endLine">The one-based line index for the end of the compilation error.</param>
20+
/// <param name="endColumn">The zero-based column index for the end of the compilation error.</param>
1121
public DiagnosticMessage(
1222
string message,
1323
string formattedMessage,
@@ -61,4 +71,4 @@ public DiagnosticMessage(
6171
/// </summary>
6272
public string FormattedMessage { get; }
6373
}
64-
}
74+
}

src/Middleware/Diagnostics.Abstractions/src/IExceptionHandlerFeature.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55

66
namespace Microsoft.AspNetCore.Diagnostics
77
{
8+
/// <summary>
9+
/// Represents a feature containing the error of the original request to be examined by an exception handler.
10+
/// </summary>
811
public interface IExceptionHandlerFeature
912
{
13+
/// <summary>
14+
/// The error encountered during the original request
15+
/// </summary>
1016
Exception Error { get; }
1117
}
12-
}
18+
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Http;
5+
46
namespace Microsoft.AspNetCore.Diagnostics
57
{
8+
/// <summary>
9+
/// Represents a feature containing the path details of the original request. This feature is provided by the
10+
/// StatusCodePagesMiddleware when it re-execute the request pipeline with an alternative path to generate the
11+
/// response body.
12+
/// </summary>
613
public interface IStatusCodeReExecuteFeature
714
{
15+
/// <summary>
16+
/// The <see cref="HttpRequest.PathBase"/> of the original request.
17+
/// </summary>
818
string OriginalPathBase { get; set; }
919

20+
/// <summary>
21+
/// The <see cref="HttpRequest.Path"/> of the original request.
22+
/// </summary>
1023
string OriginalPath { get; set; }
1124

25+
/// <summary>
26+
/// The <see cref="HttpRequest.QueryString"/> of the original request.
27+
/// </summary>
1228
string OriginalQueryString { get; set; }
1329
}
14-
}
30+
}

src/Middleware/Diagnostics.Abstractions/src/Microsoft.AspNetCore.Diagnostics.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>ASP.NET Core diagnostics middleware abstractions and feature interface definitions.</Description>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<IsAspNetCoreApp>true</IsAspNetCoreApp>
7-
<NoWarn>$(NoWarn);CS1591</NoWarn>
7+
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore;diagnostics</PackageTags>
1010
<IsPackable>false</IsPackable>

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Microsoft.AspNetCore.Builder
1010
{
11+
/// <summary>
12+
/// Extension methods for enabling <see cref="ExceptionHandlerExtensions"/>.
13+
/// </summary>
1114
public static class ExceptionHandlerExtensions
1215
{
1316
/// <summary>
@@ -95,4 +98,4 @@ public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder a
9598
return app.UseMiddleware<ExceptionHandlerMiddleware>(Options.Create(options));
9699
}
97100
}
98-
}
101+
}

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerFeature.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55

66
namespace Microsoft.AspNetCore.Diagnostics
77
{
8+
/// <summary>
9+
/// A feature containing the path and error of the original request for examination by an exception handler.
10+
/// </summary>
811
public class ExceptionHandlerFeature : IExceptionHandlerPathFeature
912
{
13+
/// <inheritdoc/>
1014
public Exception Error { get; set; }
1115

16+
/// <inheritdoc/>
1217
public string Path { get; set; }
1318
}
14-
}
19+
}

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddleware.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
namespace Microsoft.AspNetCore.Diagnostics
1616
{
17+
/// <summary>
18+
/// A middleware for handling exceptions in the application.
19+
/// </summary>
1720
public class ExceptionHandlerMiddleware
1821
{
1922
private readonly RequestDelegate _next;
@@ -22,6 +25,13 @@ public class ExceptionHandlerMiddleware
2225
private readonly Func<object, Task> _clearCacheHeadersDelegate;
2326
private readonly DiagnosticListener _diagnosticListener;
2427

28+
/// <summary>
29+
/// Creates a new <see cref="ExceptionHandlerMiddleware"/>
30+
/// </summary>
31+
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
32+
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
33+
/// <param name="options">The options for configuring the middleware.</param>
34+
/// <param name="diagnosticListener">The <see cref="DiagnosticListener"/> used for writing diagnostic messages.</param>
2535
public ExceptionHandlerMiddleware(
2636
RequestDelegate next,
2737
ILoggerFactory loggerFactory,
@@ -46,6 +56,10 @@ public ExceptionHandlerMiddleware(
4656
}
4757
}
4858

59+
/// <summary>
60+
/// Executes the middleware.
61+
/// </summary>
62+
/// <param name="context">The <see cref="HttpContext"/> for the current request.</param>
4963
public Task Invoke(HttpContext context)
5064
{
5165
ExceptionDispatchInfo edi;
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Diagnostics;
45
using Microsoft.AspNetCore.Http;
56

67
namespace Microsoft.AspNetCore.Builder
78
{
9+
/// <summary>
10+
/// Options for configuring the <see cref="ExceptionHandlerMiddleware"/>.
11+
/// </summary>
812
public class ExceptionHandlerOptions
913
{
14+
/// <summary>
15+
/// The path to the exception handling endpoint. This path will be used when executing
16+
/// the <see cref="ExceptionHandler"/>.
17+
/// </summary>
1018
public PathString ExceptionHandlingPath { get; set; }
1119

20+
/// <summary>
21+
/// The <see cref="RequestDelegate" /> that will handle the exception. If this is not
22+
/// explicitly provided, the subsequent middleware pipeline will be used by default.
23+
/// </summary>
1224
public RequestDelegate ExceptionHandler { get; set; }
1325
}
14-
}
26+
}

src/Middleware/Diagnostics/src/Microsoft.AspNetCore.Diagnostics.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>ASP.NET Core middleware for exception handling, exception display pages, and diagnostics information. Includes developer exception page middleware, exception handler middleware, runtime info middleware, status code page middleware, and welcome page middleware</Description>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<IsAspNetCoreApp>true</IsAspNetCoreApp>
7-
<NoWarn>$(NoWarn);CS1591</NoWarn>
7+
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>aspnetcore;diagnostics</PackageTags>
1010
<IsPackable>false</IsPackable>

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodeContext.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,37 @@
66

77
namespace Microsoft.AspNetCore.Diagnostics
88
{
9+
/// <summary>
10+
/// Contains information used by the handler of the <see cref="StatusCodePagesMiddleware"/>.
11+
/// </summary>
912
public class StatusCodeContext
1013
{
14+
/// <summary>
15+
/// Creates a new <see cref="StatusCodeContext"/>.
16+
/// </summary>
17+
/// <param name="context">The <see cref="HttpContext"/>.</param>
18+
/// <param name="options">The configured <see cref="StatusCodePagesOptions"/>.</param>
19+
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
1120
public StatusCodeContext(HttpContext context, StatusCodePagesOptions options, RequestDelegate next)
1221
{
1322
HttpContext = context;
1423
Options = options;
1524
Next = next;
1625
}
1726

27+
/// <summary>
28+
/// Gets the <see cref="HttpContext"/>.
29+
/// </summary>
1830
public HttpContext HttpContext { get; private set; }
1931

32+
/// <summary>
33+
/// Gets the configured <see cref="StatusCodePagesOptions"/>.
34+
/// </summary>
2035
public StatusCodePagesOptions Options { get; private set; }
2136

37+
/// <summary>
38+
/// Gets the <see cref="RequestDelegate"/> representing the next middleware in the pipeline.
39+
/// </summary>
2240
public RequestDelegate Next { get; private set; }
2341
}
24-
}
42+
}

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Microsoft.AspNetCore.Builder
1313
{
14+
/// <summary>
15+
/// Extension methods for enabling <see cref="StatusCodePagesMiddleware"/>.
16+
/// </summary>
1417
public static class StatusCodePagesExtensions
1518
{
1619
/// <summary>

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesFeature.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace Microsoft.AspNetCore.Diagnostics
88
/// </summary>
99
public class StatusCodePagesFeature : IStatusCodePagesFeature
1010
{
11+
/// <summary>
12+
/// Enables or disables status code pages. The default value is true.
13+
/// Set this to false to prevent the <see cref="StatusCodePagesMiddleware"/>
14+
/// from creating a response body while handling the error status code.
15+
/// </summary>
1116
public bool Enabled { get; set; } = true;
1217
}
13-
}
18+
}

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesMiddleware.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99

1010
namespace Microsoft.AspNetCore.Diagnostics
1111
{
12+
/// <summary>
13+
/// A middleware for generating the response body of error status codes with no body.
14+
/// </summary>
1215
public class StatusCodePagesMiddleware
1316
{
1417
private readonly RequestDelegate _next;
1518
private readonly StatusCodePagesOptions _options;
1619

20+
/// <summary>
21+
/// Creates a new <see cref="StatusCodePagesMiddleware"/>
22+
/// </summary>
23+
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
24+
/// <param name="options">The options for configuring the middleware.</param>
1725
public StatusCodePagesMiddleware(RequestDelegate next, IOptions<StatusCodePagesOptions> options)
1826
{
1927
_next = next;
@@ -24,6 +32,11 @@ public StatusCodePagesMiddleware(RequestDelegate next, IOptions<StatusCodePagesO
2432
}
2533
}
2634

35+
/// <summary>
36+
/// Executes the middleware.
37+
/// </summary>
38+
/// <param name="context">The <see cref="HttpContext"/> for the current request.</param>
39+
/// <returns>A task that represents the execution of this middleware.</returns>
2740
public async Task Invoke(HttpContext context)
2841
{
2942
var statusCodeFeature = new StatusCodePagesFeature();
@@ -52,4 +65,4 @@ public async Task Invoke(HttpContext context)
5265
await _options.HandleAsync(statusCodeContext);
5366
}
5467
}
55-
}
68+
}

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesOptions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
namespace Microsoft.AspNetCore.Builder
1212
{
1313
/// <summary>
14-
/// Options for StatusCodePagesMiddleware.
14+
/// Options for <see cref="StatusCodePagesMiddleware"/>.
1515
/// </summary>
1616
public class StatusCodePagesOptions
1717
{
18+
/// <summary>
19+
/// Creates a default <see cref="StatusCodePagesOptions"/> which produces a plaintext response
20+
/// containing the status code and the reason phrase.
21+
/// </summary>
1822
public StatusCodePagesOptions()
1923
{
2024
HandleAsync = context =>
@@ -43,6 +47,9 @@ private string BuildResponseBody(int httpStatusCode)
4347
internetExplorerWorkaround);
4448
}
4549

50+
/// <summary>
51+
/// The handler that generates the response body for the given <see cref="StatusCodeContext"/>. By default this produces a plain text response that includes the status code.
52+
/// </summary>
4653
public Func<StatusCodeContext, Task> HandleAsync { get; set; }
4754
}
48-
}
55+
}

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodeReExecuteFeature.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
namespace Microsoft.AspNetCore.Diagnostics
55
{
6+
/// <summary>Default implementation for <see cref="IStatusCodeReExecuteFeature" />.</summary>
67
public class StatusCodeReExecuteFeature : IStatusCodeReExecuteFeature
78
{
9+
/// <inheritdoc/>
810
public string OriginalPath { get; set; }
911

12+
/// <inheritdoc/>
1013
public string OriginalPathBase { get; set; }
1114

15+
/// <inheritdoc/>
1216
public string OriginalQueryString { get; set; }
1317
}
14-
}
18+
}

0 commit comments

Comments
 (0)