Exemplo n.º 1
0
        void IProtocol.Handle(TcpSocket.TcpSocketAsyncEventArgs e, byte[] data)
        {
            HttpRequest Request = e.UserToken as HttpRequest;

            if (Request == null)
            {
                Request = HttpParser.ParseRequest(data);
            }
            else
            {
                HttpParser.ParseContent(Request, data, 0, data.Length);
            }
            // ******************************************* //
            // КОСТЫЛЬ?!?!?!?!
            // ******************************************* //
            if (Request.IsContentContinueRead)
            {
                e.UserToken = Request;
                return;
            }
            e.UserToken = null;
            // ******************************************* //
            // END КОСТЫЛЬ?!?!?!?!
            // ******************************************* //

            IControllerContext context = new ControllerContext(Request);

            try
            {
                string dpasKey;
                if (!context.Request.Cookies.TryGetValue("dpas", out dpasKey))
                {
                    dpasKey = Guid.NewGuid().ToString();
                    context.Response.Cookies.Add("dpas", dpasKey);
                }

                context.SetState(dpasKey);

                if (!RequestMvcHandle(context))
                {
                    RequestHandle(context);
                }
            }
            catch (Exception ex)
            {
                RequestError(context, ex, HttpStatusCode.InternalServerError);
            }
            SendResponse(e, context);

            if (!context.Request.Header.IsSupportShouldKeepAlive)
            {
                _server.CloseConnection(e);
            }

            context.Dispose();
        }