public async Task Invoke(HttpContext context) { if (!ValidPath(context.Request)) { await _next(context); return; } string authClient = ValidClient(context.Request); if (string.IsNullOrEmpty(authClient)) { await OnForbidden(context); return; } if (context.Request.Method == HttpMethods.Post) { try { var msg = await JsonSerializer.DeserializeAsync <TaggedMessage>(context.Request.Body, _jsonOptions); msg.ClientName = authClient; msg.ReferenceId = Guid.NewGuid().ToString("N"); var status = await _mailer.Enqueue(msg); await OnSuccess(context, status); } catch (Exception ex) { await OnError(context, ex.Message); } } if (context.Request.Method == HttpMethods.Get) { string id = context.Request.Query["id"].ToString(); if (!id.HasValue()) { id = context.Request.Path.Value .Replace(_options.RequestPath, "") .Split('/') .LastOrDefault(); } await OnSuccess(context, await _mailer.GetStatus(id)); } }