Exemple #1
0
 internal abstract void ProcessRequest(HttpContext context);
Exemple #2
0
        private void AcceptTcpClient(IAsyncResult asyncResult)
        {
            var l = asyncResult.AsyncState as TcpListener;
            if (l == null) return;

            TcpClient client;
            try
            {
                client = l.EndAcceptTcpClient(asyncResult);

                ThreadPool.QueueUserWorkItem(tcpClient =>
                {
                    HttpResponse response;

                    try
                    {
                        var context = new HttpContext(client);

                        if (RequestReceived != null)
                        {
                            RequestReceived(this, context);

                            if (!context.IsHandled)
                            {
                                context.Response.StatusCode = (int) HttpStatusCode.NotFound;
                            }
                        }

                        response = context.Response;
                    }
                    catch (HttpParseException e)
                    {
                        Logger.Error(e, "QueueUserWorkItem: Caught parsing exception with return code {0}", e.ReturnCode);
                        response = new HttpResponse(e.ReturnCode);
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e, "QueueUserWorkItem: Caught unexpected exception.");
                        client.Close();
                        return;
                    }

                    if (response != null)
                    {
                        WriteResponse(response);
                    }

                    client.Close();
                }, client);
            }
            catch
            {
                // ignored
            }
            finally
            {
                l.BeginAcceptTcpClient(AcceptTcpClient, l);
            }
        }