예제 #1
0
파일: Console.cs 프로젝트: Hengle/Unity3D-1
        private void _ListenerCallback(IAsyncResult result)
        {
            var context = new ConsoleContext(this.listener.EndGetContext(result));

            _HandleRequest(context);

            this.listener.BeginGetContext(new AsyncCallback(_ListenerCallback), null);
        }
예제 #2
0
파일: Console.cs 프로젝트: Hengle/Unity3D-1
        private void _HandleRequest(ConsoleContext context)
        {
            try {
                var handled = false;
                for (; context.CurrentRoute < this.registeredRoutes.Count; ++context.CurrentRoute)
                {
                    var route = this.registeredRoutes[context.CurrentRoute];
                    var match = route.route.Match(context.Path);
                    if (!match.Success)
                    {
                        continue;
                    }

                    if (!route.methods.IsMatch(context.Request.HttpMethod))
                    {
                        continue;
                    }

                    // TODO: Main thread

                    context.Match = match;
                    route.callback(context);
                    handled = !context.Pass;
                    if (handled)
                    {
                        break;
                    }
                }

                if (!handled)
                {
                    context.Response.StatusCode        = (int)HttpStatusCode.NotFound;
                    context.Response.StatusDescription = "Not Found";
                }
            } catch (Exception exception) {
                context.Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                context.Response.StatusDescription = string.Format("Fatal error:\n{0}", exception);

                Debug.LogException(exception);
            }

            context.Response.OutputStream.Close();
        }