Skip to content

Instantly share code, notes, and snippets.

@Fodsuk
Created August 11, 2016 14:45
Show Gist options
  • Save Fodsuk/271edd5a68167a8aac47cdfb50154991 to your computer and use it in GitHub Desktop.
Save Fodsuk/271edd5a68167a8aac47cdfb50154991 to your computer and use it in GitHub Desktop.
public async Task Invoke(HttpContext context)
{
var stopWatch = new Stopwatch();
stopWatch.Start();
context.Response.OnStarting(_ =>
{
((HttpContext)_).Response.Headers["X-Instrumentation-Time-Elapsed-Ms"] = stopWatch.ElapsedMilliseconds.ToString();
return Task.FromResult(0);
}, context);
stopWatch.Stop();
await _next(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment