private HttpRequest ReadRequest(HttpResponse res) { HttpRequest req = null; try { req = reader.ReadRequest(); } catch (HttpException ex) { // create event ErrorEventArgs e = new ErrorEventArgs(ex); // invoke server.OnError(e); if (!e.Handled) { // send res.StatusCode = ex.StatusCode; // send error report if (Application.CurrentDeployment == Deployment.Production) res.Write("<b><p>Request Error</p></b><pre>" + ex.Message + "</pre>"); } } catch (Exception ex) { // status code res.StatusCode = HttpStatus.InternalServerError; // send error report try { if (Application.CurrentDeployment == Deployment.Production) res.Write("<b><p>Internal Error</p></b><pre>" + ex.ToString() + "</pre>"); } catch (Exception) { } // close and return Close(); return req; } Console.WriteLine("FINISHED occuredreq"); return req; }
/// <summary> /// Handles the request. /// </summary> private void Handle() { // create response HttpResponse res = new HttpResponse(this); HttpRequest req = null; // read request if (!Utilities.InvokeAsync(delegate() { req = ReadRequest(res);}, 1000)) { // close and return Close(); Console.WriteLine("timeout occuredreq"); return; } // handle request if (req != null) { if (Application.CurrentDeployment == Deployment.Production) { server.OnRequest(new RequestEventArgs(req, res)); } else { try { server.OnRequest(new RequestEventArgs(req, res)); } catch (Exception ex) { // create event ErrorEventArgs e = new ErrorEventArgs(new HttpException("Route exception", HttpStatus.InternalServerError, ex) { Path = req.Path, Method = req.Method}); // invoke res.Clear(); res.StatusCode = HttpStatus.InternalServerError; server.OnError(e); if (!e.Handled) { // internal error with request handler res.Write("<pre>An internal server error occured!</pre>"); } } } } // write if (!Utilities.InvokeAsync(delegate() { WriteResponse(res); }, 1000)) { // close and return Close(); Console.WriteLine("timeout occuredres"); return; } }