public async Task Invoke(HttpContext context) { var request = new WebhooksRequestForAspNetCore(context); var isRequestManagedByTweetinvi = await _accountActivityHandler.IsRequestManagedByTweetinvi(request).ConfigureAwait(false); if (isRequestManagedByTweetinvi) { var routeHandled = await _accountActivityHandler.TryRouteRequest(request).ConfigureAwait(false); if (routeHandled) { return; } } // Continue to any other request supported by the website. await _next(context).ConfigureAwait(false); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestHandler = new WebhooksRequestHandlerForWebApi(request); if (await _accountActivityRequestHandler.IsRequestManagedByTweetinvi(requestHandler).ConfigureAwait(false)) { var routeHandled = await _accountActivityRequestHandler.TryRouteRequest(requestHandler).ConfigureAwait(false); if (routeHandled) { var response = requestHandler.GetHttpResponseMessage(); var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(await tsc.Task.ConfigureAwait(false)); } } return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false)); }