public static async Task InvokeAsync(HttpContext context, CssFileWatcherService cssFileWatcherService) { if (!HttpMethods.IsPost(context.Request.Method)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return; } if (!context.Request.ContentType.Split(';').Select(s => s.Trim()).Any(s => s == "application/json")) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } var option = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var requestArgs = await JsonSerializer.DeserializeAsync <CssWatchRequestArgs>(context.Request.Body, option); foreach (var href in requestArgs.Hrefs ?? Enumerable.Empty <string>()) { cssFileWatcherService.TryAddWatch(href, requestArgs.ConnectedOnce, requestArgs.LastReloadedTime); } context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public AddCssFileWatcherMiddleware( RequestDelegate next, CssFileWatcherService cssFileWatcherService) { _next = next; _cssFileWatcherService = cssFileWatcherService; }
public CssChangedEventSourceHandler(HttpContext context, CssFileWatcherService cssFileWatcherService) { this._context = context; this._cssFileWatcherService = cssFileWatcherService; }