Beispiel #1
0
        internal ServerRequest(HttpServerRequest httpRequest, UrlData urlData, ServerRoute route)
        {
            _httpRequest = httpRequest;

            _urlData = urlData;
            _route = route;
        }
Beispiel #2
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);
        }