Пример #1
0
        private void OnHttpServerRequest(HttpServerRequest httpRequest, HttpServerResponse httpResponse)
        {
            UrlData     urlData = Url.Parse(httpRequest.Url, /* parseQueryString */ true);
            ServerRoute route   = _router.Match(urlData.PathName);

            Action <Exception> errorHandler = delegate(Exception e) {
                httpResponse.WriteHead(HttpStatusCode.InternalServerError, e.Message);
                httpResponse.End();

                Runtime.TraceInfo("500 : %s %s", httpRequest.Method, httpRequest.Url);
                return;
            };

            ServerRequest         request      = new ServerRequest(httpRequest, urlData, route);
            Task <ServerResponse> responseTask = null;

            try {
                responseTask = _modules[0].ProcessRequest(request);
            }
            catch (Exception e) {
                errorHandler(e);
                return;
            }

            responseTask.Done(delegate(ServerResponse response) {
                response.Write(httpResponse);

                Runtime.TraceInfo("%d : %s %s", response.StatusCode, httpRequest.Method, httpRequest.Url);
            })
            .Fail(errorHandler);
        }
Пример #2
0
        public Task<ServerResponse> ProcessRequest(ServerRequest request)
        {
            // The runtime is a server module, which is logically at the end of the module
            // pipeline (i.e. doesn't wrap another module), and it is responsible for executing
            // the handler associated with the current route, or generating a not found response.

            IServerHandler handler = null;

            ServerRoute route = request.Route;
            if (route != null) {
                handler = route.Handler;
            }

            if (handler != null) {
                return handler.ProcessRequest(request);
            }
            else {
                return Deferred.Create<ServerResponse>(ServerResponse.NotFound).Task;
            }
        }
Пример #3
0
        public Task <ServerResponse> ProcessRequest(ServerRequest request)
        {
            // The runtime is a server module, which is logically at the end of the module
            // pipeline (i.e. doesn't wrap another module), and it is responsible for executing
            // the handler associated with the current route, or generating a not found response.

            IServerHandler handler = null;

            ServerRoute route = request.Route;

            if (route != null)
            {
                handler = route.Handler;
            }

            if (handler != null)
            {
                return(handler.ProcessRequest(request));
            }
            else
            {
                return(Deferred.Create <ServerResponse>(ServerResponse.NotFound).Task);
            }
        }
Пример #4
0
        private void OnHttpServerRequest(HttpServerRequest httpRequest, HttpServerResponse httpResponse)
        {
            UrlData urlData = Url.Parse(httpRequest.Url, /* parseQueryString */ true);
            ServerRoute route = _router.Match(urlData.PathName);

            Action<Exception> errorHandler = delegate(Exception e) {
                httpResponse.WriteHead(HttpStatusCode.InternalServerError, e.Message);
                httpResponse.End();

                Runtime.TraceInfo("500 : %s %s", httpRequest.Method, httpRequest.Url);
                return;
            };

            ServerRequest request = new ServerRequest(httpRequest, urlData, route);
            Task<ServerResponse> responseTask = null;

            try {
                responseTask = _modules[0].ProcessRequest(request);
            }
            catch (Exception e) {
                errorHandler(e);
                return;
            }

            responseTask.Done(delegate(ServerResponse response) {
                response.Write(httpResponse);

                Runtime.TraceInfo("%d : %s %s", response.StatusCode, httpRequest.Method, httpRequest.Url);
            })
            .Fail(errorHandler);
        }