Tips For Creating A Minimal Code Sample

From time to time it might be helpful to create a minimal code sample. This will be useful when submitting PRs, writing documentation, asking questions, or reporting bugs.

The fastest way to create a minimal code sample would be:

Step 1: Create new ASP .NET Core WebAPI project

Step 2: Add the OwaspHeaders.Core package

Step 3: Add the SecureHeadersMiddleware to the ASP .NET Core Middleware pipeline:

// in Program.cs
app.UseSecureHeadersMiddleware();

Optional: To see logging output, configure logging. The following is an example, modify it to suit your needs:

// in Program.cs (before building the app)
builder.Logging.AddConsole();
builder.Logging.SetMinimumLevel(LogLevel.Information);

// Then use the middleware
app.UseSecureHeadersMiddleware();

This will show SecureHeaders operations in the console output with Event IDs 1001-1005.

Step 4: Progressively add smaller and smaller features until you hit on the bug, issue, or have added the new feature (dependent on what the code sample is for).

Step 5: If small enough, add the code sample as a comment, issue or PR. If not, create a GitHub Gist for it, and link to it in as a comment, issue or PR.