Exemplo n.º 1
0
 public bool ProcessAsync(ProcessRequestEventArgs args)
 {
     pageViews++;
     double cpu = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds / stopwatch.Elapsed.TotalSeconds;
     string html = "<html>";
     html += "<h1>System Statistics</h1>";
     html += "<ul>";
     html += string.Format("<li>Uptime: {0} <br/></li>", ToReadableString(stopwatch.Elapsed));
     html += string.Format("<li>CPU usage: {0:P2} <br/></li>", cpu);
     html += string.Format("<li>Total processor time: {0}<br/></li>", ToReadableString(Process.GetCurrentProcess().TotalProcessorTime));
     html += string.Format("<li>Working set: {0}<br/></li>", BytesToString(Process.GetCurrentProcess().WorkingSet64));
     html += string.Format("<li>Total bytes downloaded: {0}<br/></li>", BytesToString(m.TotalReceivedBytes()));
     html += string.Format("<li>Total bytes uploaded: {0}<br/></li>", BytesToString(m.TotalSentBytes()));
     html += "</ul>";
     html += string.Format("Page accessed <b>{0}</b> times.<br/>", pageViews);
     html += "</html>";
     args.Response.Producer = new BufferedProducer(html);
     return false;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Async event handles HTTP requests received.
        /// </summary>
        /// <param name="request"></param>
        void ProcessRequest(HttpRequest request)
        {
            var handledByModule = false;

            lock (_modules)
            {
                foreach (var module in _modules)
                {
                    if (module.ResponsibleForRequest(request))
                    {
                        handledByModule = true;
                        var args = new ProcessRequestEventArgs();
                        args.Request  = request;
                        args.Response = new HttpResponse()
                        {
                            HttpVersion = request.Version,
                            StatusCode  = HttpStatusCode.OK,
                            Connection  = HttpConnection.Close,
                            Headers     = new Dictionary <string, string>()
                        };
                        args.Completed += ModuleProcessComplete;
                        if (!module.ProcessAsync(args))
                        {
                            ModuleProcessComplete(module, args);
                        }
                    }
                }
            }
            if (!handledByModule)
            {
                var response = new HttpResponse();
                response.StatusCode = HttpStatusCode.NotFound;
                response.Headers.Add("Content-Type", "text/plain");
                response.Producer = new BufferedProducer("404 - Not Found");
                var writer = new HttpResponseWriter(request.ClientSocket);
                writer.AsyncWrite(request, response);
            }
        }
Exemplo n.º 3
0
    public bool ProcessAsync(FragLabs.HTTP.ProcessRequestEventArgs args)
    {
        string        html    = "<html>";
        List <string> modules = new List <string>();

        foreach (var m in server.httpModules)
        {
            modules.Add(m.name);
        }
        modules.Sort();
        foreach (string s in modules)
        {
            foreach (var m in server.httpModules)
            {
                if (m.name == s)
                {
                    html += string.Format("<a href='{0}'>{0}</a> - {1}", m.name, m.description());
                }
            }
        }
        html += "</html>";
        args.Response.Producer = new FragLabs.HTTP.BufferedProducer(html);
        return(false);
    }
Exemplo n.º 4
0
 /// <summary>
 /// Async event handles HTTP requests received.
 /// </summary>
 /// <param name="request"></param>
 void ProcessRequest(HttpRequest request)
 {
     var handledByModule = false;
     lock (_modules)
     {
         foreach (var module in _modules)
         {
             if (module.ResponsibleForRequest(request))
             {
                 handledByModule = true;
                 var args = new ProcessRequestEventArgs();
                 args.Request = request;
                 args.Response = new HttpResponse()
                 {
                     HttpVersion = request.Version,
                     StatusCode = HttpStatusCode.OK,
                     Connection = HttpConnection.Close,
                     Headers = new Dictionary<string,string>()
                 };
                 args.Completed += ModuleProcessComplete;
                 if (!module.ProcessAsync(args))
                     ModuleProcessComplete(module, args);
             }
         }
     }
     if (!handledByModule)
     {
         var response = new HttpResponse();
         response.StatusCode = HttpStatusCode.NotFound;
         response.Headers.Add("Content-Type", "text/plain");
         response.Producer = new BufferedProducer("404 - Not Found");
         var writer = new HttpResponseWriter(request.ClientSocket);
         writer.AsyncWrite(request, response);
     }
 }
Exemplo n.º 5
0
 void ModuleProcessComplete(object sender, ProcessRequestEventArgs e)
 {
     var writer = new HttpResponseWriter(e.Request.ClientSocket);
     writer.AsyncWrite(e.Request, e.Response);
 }
Exemplo n.º 6
0
        void ModuleProcessComplete(object sender, ProcessRequestEventArgs e)
        {
            var writer = new HttpResponseWriter(e.Request.ClientSocket);

            writer.AsyncWrite(e.Request, e.Response);
        }