private void ProcessRequest(Object stateInfo) { CHttpRequest request = (CHttpRequest)stateInfo; bool processed = false; int counter = 0; try { while ((!processed) && (counter <= handlerTypes.Length - 1)) { CHttpHandler handler = (CHttpHandler)CreateHandler(handlerTypes[counter]); processed = handler.ProcessRequest(request); if (processed) { serverLog.LogInfo("Request " + request.RequestId + " HTTP " + request.Request.HttpMethod + " " + request.Request.Url + " was handled by " + handler.ToString()); } counter++; } if (!processed) { CHttpResponse response = new CHttpTextResponse("Sorry, request not handled"); response.SendResponse(HttpStatusCode.OK, request); serverLog.LogWarn("Request " + request.RequestId + " was not handled by any handler"); } } catch (Exception e) { serverLog.LogError("Got error while processing " + request.RequestId + " " + e.Message); request.SendServerError(request); } }
private bool ValidateSession(CHttpRequest arequest) { Cookie sessionCookie = arequest.Request.Cookies["sessionId"]; CHttpSession sessionObject = null; if ((sessionCookie == null) || ((sessionCookie != null) && (sessionCookie.Value == ""))) { sessionObject = arequest.Server.ServerSessions.GetSession(""); arequest.Response.Cookies.Add(new Cookie("sessionId", sessionObject.SessionId)); } else { sessionObject = arequest.Server.ServerSessions.GetSession(sessionCookie.Value); } if (sessionObject != null) { try { sessionObject.TouchTime = DateTime.Now; arequest.Session = sessionObject; CHttpResponse response = new CHttpTextResponse("Hello with session id " + sessionObject.SessionId + " touchTime " + sessionObject.TouchTime.ToString()); response.SendResponse(HttpStatusCode.OK, arequest); } finally { arequest.Session.IsUsed = false; } } else { arequest.Response.Cookies.Add(new Cookie("sessionId", "")); arequest.SendServerExpired(arequest); } return(true); }
public void SendServerError(CHttpRequest arequest) { CHttpResponse response = new CHttpTextResponse("Server error"); response.SendResponse(HttpStatusCode.InternalServerError, arequest); }
public void SendServerExpired(CHttpRequest arequest) { CHttpResponse response = new CHttpTextResponse("Session expired"); response.SendResponse(HttpStatusCode.Forbidden, arequest); }
public void SendServerOverloaded(CHttpRequest arequest) { CHttpResponse response = new CHttpTextResponse("Sever overloaded"); response.SendResponse(HttpStatusCode.ServiceUnavailable, arequest); }