private void MainThreadHandler() { listener = new HttpListener("http"); bool abortRequested = false; listener.Start(); //TODO: Threading verhaal nog te bekijken !! while (!abortRequested) { try { Debug.Print("Webserver while loop beginning"); var context = listener.GetContext(); var path = context.Request.Url.OriginalString; var method = context.Request.HttpMethod.HttpMethodParse(); //Debug.Print("Webserver incoming request : '" + url + "'"); WebResponse response = new NotFoundResponse(path); if (routeList.Contains(method, path)) { var route = routeList.Find(method, path); if (route.IsFileResponse) { string content = (string)ResourceUtility.GetObject(resourceManager, route.FileResource); response = new FileResponse(content, route.ContentType); } else { var webRequest = new WebRequest(context.Request); response = route.RequestHandler(webRequest); } } response.Respond(context); context.Close(); } catch (Exception exception) { listener.Stop(); listener.Close(); abortRequested = true; } } }
private void MainThreadHandler() { listener = new HttpListener("http"); bool abortRequested = false; listener.Start(); //TODO: Threading verhaal nog te bekijken !! while (!abortRequested) { try { Debug.Print("Webserver while loop beginning"); var context = listener.GetContext(); var path = context.Request.Url.OriginalString; var method = context.Request.HttpMethod.HttpMethodParse(); //Debug.Print("Webserver incoming request : '" + url + "'"); WebResponse response = new NotFoundResponse(path); if (routeList.Contains(method, path)) { var route = routeList.Find(method, path); if (route.IsFileResponse) { string content = (string) ResourceUtility.GetObject(resourceManager, route.FileResource); response = new FileResponse(content, route.ContentType); } else { var webRequest = new WebRequest(context.Request); response = route.RequestHandler(webRequest); } } response.Respond(context); context.Close(); } catch (Exception exception) { listener.Stop(); listener.Close(); abortRequested = true; } } }