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); }
internal void Write(HttpServerResponse httpResponse) { httpResponse.WriteHead(_statusCode, _headers); if (_content != null) { httpResponse.Write(_content, Encoding.UTF8); } httpResponse.End(); }
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); }