Skip to content

Commit a759d4e

Browse files
committed
debug lvl middleware
1 parent 847f4bf commit a759d4e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

scenarios/tls.benchmarks.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ jobs:
1717
variables:
1818
mTLS: false # enables settings on http.sys to negotiate client cert on connections
1919
tlsRenegotiation: false # enables client cert validation
20+
tlsProtocols: "tls12"
21+
# debug purpose settings
2022
certValidationConsoleEnabled: false
2123
httpSysLogs: false
2224
statsEnabled: false
23-
tlsProtocols: "tls12"
24-
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --httpSysLogs {{httpSysLogs}} --tlsProtocols {{tlsProtocols}}"
25+
logRequestInfo: false
26+
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --httpSysLogs {{httpSysLogs}} --tlsProtocols {{tlsProtocols}} --logRequestInfo {{logRequestInfo}}"
2527

2628
kestrelServer:
2729
source:

src/BenchmarksApps/TLS/HttpSys/Program.cs

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

99
var writeCertValidationEventsToConsole = bool.TryParse(builder.Configuration["certValidationConsoleEnabled"], out var certValidationConsoleEnabled) && certValidationConsoleEnabled;
1010
var httpSysLoggingEnabled = bool.TryParse(builder.Configuration["httpSysLogs"], out var httpSysLogsEnabled) && httpSysLogsEnabled;
11+
var logRequestInfo = bool.TryParse(builder.Configuration["logRequestInfo"], out var logRequestInfoConfig) && logRequestInfoConfig;
1112
var statsEnabled = bool.TryParse(builder.Configuration["statsEnabled"], out var connectionStatsEnabledConfig) && connectionStatsEnabledConfig;
13+
1214
var mTlsEnabled = bool.TryParse(builder.Configuration["mTLS"], out var mTlsEnabledConfig) && mTlsEnabledConfig;
1315
var tlsRenegotiationEnabled = bool.TryParse(builder.Configuration["tlsRenegotiation"], out var tlsRenegotiationEnabledConfig) && tlsRenegotiationEnabledConfig;
1416
var listeningEndpoints = builder.Configuration["urls"] ?? "https://localhost:5000/";
@@ -78,6 +80,23 @@ void OnShutdown()
7880
}
7981
}
8082

83+
if (logRequestInfo)
84+
{
85+
Console.WriteLine("Registered request logging middleware");
86+
var logged = false;
87+
88+
app.Use(async (context, next) =>
89+
{
90+
if (!logged)
91+
{
92+
logged = true;
93+
Console.WriteLine("TLS Protocol: " + context.Features.Get<ITlsHandshakeFeature>()?.Protocol);
94+
}
95+
96+
await next();
97+
});
98+
}
99+
81100
if (tlsRenegotiationEnabled)
82101
{
83102
// this is an http.sys middleware to get a cert
@@ -89,7 +108,6 @@ void OnShutdown()
89108
{
90109
if (writeCertValidationEventsToConsole)
91110
{
92-
Console.WriteLine("Protocol: " + context.Features.Get<ITlsHandshakeFeature>()?.Protocol);
93111
Console.WriteLine($"No client certificate provided. Fetching for connection {context.Connection.Id}");
94112
}
95113

0 commit comments

Comments
 (0)