public async Task InvokeAsync(HttpContext httpContext, string routeTemplate) { var request = httpContext.Request; if ("GET".Equals(request.HttpMethod, StringComparison.OrdinalIgnoreCase)) { var routeValues = new RouteValueDictionary(); var templateMatcher = new TemplateMatcher(TemplateParser.Parse(routeTemplate), routeValues); if (templateMatcher.TryMatch(request.Path, routeValues)) { var response = httpContext.Response; var jsonQLRequest = new JsonQLRequest(httpContext, jsonQLOptions); var authorized = jsonQLOptions.AuthorizeAsync == null || await jsonQLOptions.AuthorizeAsync(jsonQLRequest); if (authorized) { var result = await new JsonQLHandler(jsonQLOptions, jsonQLResourceTable).HandleAsync(jsonQLRequest); response.Clear(); response.StatusCode = 200; response.ContentType = "application/json"; response.Write(result); } else { response.StatusCode = 403; } response.End(); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="next"></param> /// <returns></returns> public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var jsonQLRequest = new JsonQLRequest(context, jsonQLOptions); var authorized = jsonQLOptions.AuthorizeAsync == null ? true : await jsonQLOptions.AuthorizeAsync(jsonQLRequest); var response = context.Response; if (authorized) { var result = await new JsonQLHandler(jsonQLOptions, jsonQLResourceTable).HandleAsync(jsonQLRequest); response.Clear(); response.StatusCode = 200; response.ContentType = "application/json"; await response.WriteAsync(result); } else { response.StatusCode = 403; } }