Ejemplo n.º 1
0
        static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host)
        {
            try
            {
                // Get the response action to take:
                Stopwatch sw = Stopwatch.StartNew();
                var requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User);
                var action = await host._handler.Execute(requestContext);
                sw.Stop();

                if (sw.ElapsedMilliseconds <= 20) Interlocked.Increment(ref _20s);
                else if (sw.ElapsedMilliseconds <= 50) Interlocked.Increment(ref _50s);
                else if (sw.ElapsedMilliseconds <= 100) Interlocked.Increment(ref _100s);
                else if (sw.ElapsedMilliseconds <= 200) Interlocked.Increment(ref _200s);
                else if (sw.ElapsedMilliseconds <= 500) Interlocked.Increment(ref _500s);
                else if (sw.ElapsedMilliseconds <= 1000) Interlocked.Increment(ref _1000s);
                else if (sw.ElapsedMilliseconds <= 2000) Interlocked.Increment(ref _2000s);
                else if (sw.ElapsedMilliseconds <= 5000) Interlocked.Increment(ref _5000s);
                else
                {
                    TraceLog.WriteError("Http request [{0}] timeout {1}ms", listenerContext.Request.RawUrl, sw.ElapsedMilliseconds);
                    Interlocked.Increment(ref _up);
                }
                if (action != null)
                {
                    // Take the action and await its completion:
                    var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response);
                    var task = action.Execute(responseContext);
                    if (task != null) await task;
                }

                // Close the response and send it to the client:
                listenerContext.Response.Close();
            }
            catch (HttpListenerException)
            {
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Http ProcessListenerContext {0}", ex);
            }
        }
Ejemplo n.º 2
0
        static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host)
        {
            try
            {
                // Get the response action to take:
                Stopwatch sw             = Stopwatch.StartNew();
                var       requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User);
                var       action         = await host._handler.Execute(requestContext);

                sw.Stop();

                if (sw.ElapsedMilliseconds <= 20)
                {
                    Interlocked.Increment(ref _20s);
                }
                else if (sw.ElapsedMilliseconds <= 50)
                {
                    Interlocked.Increment(ref _50s);
                }
                else if (sw.ElapsedMilliseconds <= 100)
                {
                    Interlocked.Increment(ref _100s);
                }
                else if (sw.ElapsedMilliseconds <= 200)
                {
                    Interlocked.Increment(ref _200s);
                }
                else if (sw.ElapsedMilliseconds <= 500)
                {
                    Interlocked.Increment(ref _500s);
                }
                else if (sw.ElapsedMilliseconds <= 1000)
                {
                    Interlocked.Increment(ref _1000s);
                }
                else if (sw.ElapsedMilliseconds <= 2000)
                {
                    Interlocked.Increment(ref _2000s);
                }
                else if (sw.ElapsedMilliseconds <= 5000)
                {
                    Interlocked.Increment(ref _5000s);
                }
                else
                {
                    TraceLog.WriteError("Http request [{0}] timeout {1}ms", listenerContext.Request.RawUrl, sw.ElapsedMilliseconds);
                    Interlocked.Increment(ref _up);
                }
                if (action != null)
                {
                    // Take the action and await its completion:
                    var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response);
                    var task            = action.Execute(responseContext);
                    if (task != null)
                    {
                        await task;
                    }
                }

                // Close the response and send it to the client:
                listenerContext.Response.Close();
            }
            catch (HttpListenerException)
            {
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Http ProcessListenerContext {0}", ex);
            }
        }
Ejemplo n.º 3
0
        static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host)
        {
            Stopwatch sw              = Stopwatch.StartNew();
            string    rawUrl          = string.Empty;
            string    userHostAddress = string.Empty;
            long      actionTime      = 0;
            string    identity        = string.Empty;

            try
            {
                rawUrl          = listenerContext.Request.RawUrl;
                userHostAddress = host.HttpCdnAddress.GetUserHostAddress(listenerContext.Request.RemoteEndPoint, key => listenerContext.Request.Headers[key]);
                // Get the response action to take:
                var requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User, userHostAddress);
                var action         = await host._handler.Execute(requestContext);

                actionTime = sw.ElapsedMilliseconds;

                if (action != null)
                {
                    if (listenerContext.Request.HttpMethod == "POST")
                    {
                        rawUrl += action.RequestParams;
                    }
                    identity = action.Identity;
                    // Take the action and await its completion:
                    var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response);
                    var task            = action.Execute(responseContext);
                    if (task != null)
                    {
                        await task;
                    }
                }
                // Close the response and send it to the client:
                listenerContext.Response.Close();
                sw.Stop();
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Http ProcessListenerContext {0}\r\nUrl:{1}\r\nHost:{2}, User:{3}", ex, rawUrl, userHostAddress, identity);
            }
            finally
            {
                if (sw.ElapsedMilliseconds >= 5)
                {
                    TraceLog.Write("Http request action time:{0}ms, total:{1}ms.\r\nRawUrl:{2}\r\nHost:{3}, User:{4}", actionTime, sw.ElapsedMilliseconds, rawUrl, userHostAddress, identity);
                }
                if (sw.ElapsedMilliseconds == 0)
                {
                }
                else if (sw.ElapsedMilliseconds <= 20)
                {
                    Interlocked.Increment(ref _20s);
                }
                else if (sw.ElapsedMilliseconds <= 50)
                {
                    Interlocked.Increment(ref _50s);
                }
                else if (sw.ElapsedMilliseconds <= 100)
                {
                    Interlocked.Increment(ref _100s);
                }
                else if (sw.ElapsedMilliseconds <= 200)
                {
                    Interlocked.Increment(ref _200s);
                }
                else if (sw.ElapsedMilliseconds <= 500)
                {
                    Interlocked.Increment(ref _500s);
                }
                else if (sw.ElapsedMilliseconds <= 1000)
                {
                    Interlocked.Increment(ref _1000s);
                }
                else if (sw.ElapsedMilliseconds <= 2000)
                {
                    Interlocked.Increment(ref _2000s);
                }
                else if (sw.ElapsedMilliseconds <= 5000)
                {
                    Interlocked.Increment(ref _5000s);
                }
                else
                {
                    TraceLog.WriteError("Http request action timeout:{0}ms, total:{1}ms.\r\nRawUrl:{2}\r\nHost:{3}, User:{4}", actionTime, sw.ElapsedMilliseconds, rawUrl, userHostAddress, identity);
                    Interlocked.Increment(ref _up);
                }
            }
        }
Ejemplo n.º 4
0
        static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host)
        {
            Stopwatch sw = Stopwatch.StartNew();
            string rawUrl = string.Empty;
            string userHostAddress = string.Empty;
            long actionTime = 0;
            string identity = string.Empty;
            try
            {
                rawUrl = listenerContext.Request.RawUrl;
                userHostAddress = host.HttpCdnAddress.GetUserHostAddress(listenerContext.Request.RemoteEndPoint, key => listenerContext.Request.Headers[key]);
                // Get the response action to take:
                var requestContext = new HttpRequestContext(host._hostContext, listenerContext.Request, listenerContext.User, userHostAddress);
                var action = await host._handler.Execute(requestContext);
                actionTime = sw.ElapsedMilliseconds;

                if (action != null)
                {
                    if (listenerContext.Request.HttpMethod == "POST")
                    {
                        rawUrl += action.RequestParams;
                    }
                    identity = action.Identity;
                    // Take the action and await its completion:
                    var responseContext = new HttpRequestResponseContext(requestContext, listenerContext.Response);
                    var task = action.Execute(responseContext);
                    if (task != null) await task;
                }
                // Close the response and send it to the client:
                listenerContext.Response.Close();
                sw.Stop();
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Http ProcessListenerContext {0}\r\nUrl:{1}\r\nHost:{2}, User:{3}", ex, rawUrl, userHostAddress, identity);
            }
            finally
            {
                if (sw.ElapsedMilliseconds >= 5)
                {
                    TraceLog.Write("Http request action time:{0}ms, total:{1}ms.\r\nRawUrl:{2}\r\nHost:{3}, User:{4}", actionTime, sw.ElapsedMilliseconds, rawUrl, userHostAddress, identity);
                }
                if (sw.ElapsedMilliseconds == 0) { }
                else if (sw.ElapsedMilliseconds <= 20) Interlocked.Increment(ref _20s);
                else if (sw.ElapsedMilliseconds <= 50) Interlocked.Increment(ref _50s);
                else if (sw.ElapsedMilliseconds <= 100) Interlocked.Increment(ref _100s);
                else if (sw.ElapsedMilliseconds <= 200) Interlocked.Increment(ref _200s);
                else if (sw.ElapsedMilliseconds <= 500) Interlocked.Increment(ref _500s);
                else if (sw.ElapsedMilliseconds <= 1000) Interlocked.Increment(ref _1000s);
                else if (sw.ElapsedMilliseconds <= 2000) Interlocked.Increment(ref _2000s);
                else if (sw.ElapsedMilliseconds <= 5000) Interlocked.Increment(ref _5000s);
                else
                {
                    TraceLog.WriteError("Http request action timeout:{0}ms, total:{1}ms.\r\nRawUrl:{2}\r\nHost:{3}, User:{4}", actionTime, sw.ElapsedMilliseconds, rawUrl, userHostAddress, identity);
                    Interlocked.Increment(ref _up);
                }

            }
        }