private bool HandleClientRequest(HttpClientHandler clientHandler, HttpContext httpContext)
        {
            var eventArgs = new HttpRequestReceivedEventArgs(httpContext);

            RequestReceived?.Invoke(clientHandler, eventArgs);

            return(eventArgs.IsHandled);
        }
Beispiel #2
0
 private void HandleHttpRequest(HttpRequestReceivedEventArgs e)
 {
     try
     {
         HttpRequestReceived?.Invoke(this, e);
     }
     finally
     {
         if (_webSocketClientSession == null)
         {
             if (!e.IsHandled || e.Context.Request.Headers.GetConnectionMustBeClosed())
             {
                 _cancellationTokenSource.Cancel();
             }
         }
     }
 }
        private bool HandleClientRequest(HttpClientHandler clientHandler, HttpContext httpContext)
        {
            var handlerCollection = RequestReceived;

            if (handlerCollection == null)
            {
                return(false);
            }

            var eventArgs = new HttpRequestReceivedEventArgs(httpContext);

            foreach (var handler in handlerCollection.GetInvocationList())
            {
                handler.DynamicInvoke(this, eventArgs);
                if (eventArgs.IsHandled)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        private void ExecuteActions(object sender, HttpRequestReceivedEventArgs e)
        {
            string requestUri = e.Context.Request.Uri.Trim('/');

            if (!requestUri.StartsWith(_baseUri, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            string relativeUri = requestUri.Substring(_baseUri.Length).Trim('/');

            foreach (var handler in _handlers)
            {
                if (!handler.Method.Equals(e.Context.Request.Method))
                {
                    continue;
                }

                if (handler.HandleRequestsWithDifferentSubUrl)
                {
                    if (!relativeUri.StartsWith(handler.Uri, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!handler.Uri.Equals(relativeUri, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                InvokeHandlerAction(handler, e.Context);
                e.IsHandled = true;
                return;
            }
        }