예제 #1
0
        void ProcessHttpError(HttpStatusCode httpStatusCode, HttpRequest request)
        {
            var response = new HttpResponse();

            response.StatusCode = httpStatusCode;
            response.Producer   = new BufferedProducer("An error occurred, please hang tight");
            var writer = new HttpResponseWriter(request.ClientSocket);

            writer.AsyncWrite(request, response);
        }
예제 #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);
            }
        }
예제 #3
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);
     }
 }
예제 #4
0
 void ProcessHttpError(HttpStatusCode httpStatusCode, HttpRequest request)
 {
     var response = new HttpResponse();
     response.StatusCode = httpStatusCode;
     response.Producer = new BufferedProducer("An error occurred, please hang tight");
     var writer = new HttpResponseWriter(request.ClientSocket);
     writer.AsyncWrite(request, response);
 }
예제 #5
0
 void ModuleProcessComplete(object sender, ProcessRequestEventArgs e)
 {
     var writer = new HttpResponseWriter(e.Request.ClientSocket);
     writer.AsyncWrite(e.Request, e.Response);
 }
예제 #6
0
        void ModuleProcessComplete(object sender, ProcessRequestEventArgs e)
        {
            var writer = new HttpResponseWriter(e.Request.ClientSocket);

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