public static string GetRequestMethod(this OwinRequestScopeContext context) { return(context.IfNotNull( c => c.OwinContext.IfNotNull( oc => oc.Request.IfNotNull( r => r.Method)))); }
public static int GetResponseStatusCode(this OwinRequestScopeContext context) { return(context.IfNotNull( c => c.OwinContext.IfNotNull( oc => oc.Response.IfNotNull( r => r.StatusCode)))); }
public async Task Invoke(IDictionary <string, object> environment) { if (environment.ContainsKey(EnvironmentKey)) { // No need to create another scope, and no need to dispose it. // Just set it as current on the CallContext, and pass the request to the next module in pipeline. OwinRequestScopeContext.Current = (OwinRequestScopeContext)environment[EnvironmentKey]; await _next(environment); } else { // This is the first time the module appears in the pipeline. // Create a new scope, set it in environment, and clean-up after the pipeline is complete. var scopeContext = new OwinRequestScopeContext(environment); environment[EnvironmentKey] = scopeContext; OwinRequestScopeContext.Current = scopeContext; try { await _next(environment); } finally { try { scopeContext.Complete(); } finally { OwinRequestScopeContext.FreeContextSlot(); } } } }
public static bool IsSuccess(this OwinRequestScopeContext context) { var status = context.GetResponseStatusCode(); return(status >= 200 && status < 300); }
public static bool IsGet(this OwinRequestScopeContext context) { return((context.GetRequestMethod() ?? "").ToUpper().Equals("GET")); }