Skip to content

Commit 4a72030

Browse files
committed
Add a debug info page
1 parent c887a18 commit 4a72030

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNet.Builder;
7+
using Microsoft.AspNet.Hosting;
8+
using Microsoft.AspNet.Http;
9+
using Microsoft.Extensions.PlatformAbstractions;
10+
11+
namespace Benchmarks
12+
{
13+
public class DebugInfoPageMiddleware
14+
{
15+
private static readonly PathString _path = new PathString("/debug");
16+
#if DEBUG
17+
private static readonly string _configurationName = "Debug";
18+
#elif RELEASE
19+
private static readonly string _configurationName = "Release";
20+
#else
21+
private static readonly string _configurationName = "";
22+
#endif
23+
24+
private readonly IApplicationEnvironment _appEnv;
25+
private readonly IHostingEnvironment _hostingEnv;
26+
private readonly RequestDelegate _next;
27+
28+
public DebugInfoPageMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, IApplicationEnvironment appEnv)
29+
{
30+
_next = next;
31+
_hostingEnv = hostingEnv;
32+
_appEnv = appEnv;
33+
}
34+
35+
public async Task Invoke(HttpContext httpContext)
36+
{
37+
// We check Ordinal explicitly first because it's faster than OrdinalIgnoreCase
38+
if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal) ||
39+
httpContext.Request.Path.StartsWithSegments(_path, StringComparison.OrdinalIgnoreCase))
40+
{
41+
httpContext.Response.ContentType = "text/html";
42+
43+
await httpContext.Response.WriteAsync("<h1>Application Information</h1>");
44+
await httpContext.Response.WriteAsync("<ul>");
45+
46+
await httpContext.Response.WriteAsync($"<li>Environment: {_hostingEnv.EnvironmentName}</li>");
47+
await httpContext.Response.WriteAsync($"<li>Framework: {_appEnv.RuntimeFramework.FullName}</li>");
48+
await httpContext.Response.WriteAsync($"<li>Configuration: {_configurationName}</li>");
49+
await httpContext.Response.WriteAsync($"<li>Server: {_hostingEnv.Configuration["server"]}</li>");
50+
await httpContext.Response.WriteAsync($"<li>Server URLs: {_hostingEnv.Configuration["server.urls"]}</li>");
51+
52+
await httpContext.Response.WriteAsync($"<li>Server features:<ol>");
53+
foreach (var feature in httpContext.Features)
54+
{
55+
await httpContext.Response.WriteAsync($"<li>{feature.Key.Name}</li>");
56+
}
57+
await httpContext.Response.WriteAsync($"</ol></li>");
58+
59+
await httpContext.Response.WriteAsync("</ul>");
60+
61+
return;
62+
}
63+
64+
await _next(httpContext);
65+
}
66+
}
67+
68+
public static class DebugInfoPageMiddlewareExtensions
69+
{
70+
public static IApplicationBuilder UseDebugInfoPage(this IApplicationBuilder builder)
71+
{
72+
return builder.UseMiddleware<DebugInfoPageMiddleware>();
73+
}
74+
}
75+
}

src/Benchmarks/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public void Configure(IApplicationBuilder app)
9999
Console.WriteLine("Static file tests enabled");
100100
}
101101

102+
app.UseDebugInfoPage();
103+
102104
app.Run(context => context.Response.WriteAsync("Try /plaintext instead"));
103105
}
104106

src/Benchmarks/wwwroot/16KB.txt

16 KB
Binary file not shown.

0 commit comments

Comments
 (0)