Skip to content

Instantly share code, notes, and snippets.

@FSou1 FSou1/HttpPropertyKeys.cs
Last active Jan 13, 2017

Embed
What would you like to do?
Simple uptime monitoring owin's middleware (just for catching "<url>/uptime" requests)
public static class HttpPropertyKeys
{
public static readonly string UptimeMiddlewarePath = "/uptime";
}
public class UptimeMonitoringMiddleware
{
public UptimeMonitoringMiddleware(
Func<IDictionary<string, object>, Task> next, string path)
{
_next = next;
_path = path;
}
public async Task Invoke(IDictionary<string, object> environment)
{
var context = new OwinContext(environment);
if (context.Request.Path == PathString.FromUriComponent(_path ?? HttpPropertyKeys.UptimeMiddlewarePath))
{
await context.Response.WriteAsync("Uptime status: OK");
return;
}
await _next(environment);
}
private readonly Func<IDictionary<string, object>, Task> _next;
private readonly string _path;
}
public static class UptimeMiddlewareExtension
{
public static IAppBuilder UseUptimeMonitoringMiddleware(this IAppBuilder app, string path = null)
{
app.Use(typeof(UptimeMonitoringMiddleware), path);
return app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.