public void FailSession(int iError, string sErrorStatusText, string sErrorBody) { this.m_session.SetBitFlag(SessionFlags.ResponseGeneratedByKProxy, true); if ((iError >= 400) && (sErrorBody.Length < 0x200)) { sErrorBody = sErrorBody.PadRight(0x200, ' '); } this.m_session.responseBodyBytes = Encoding.UTF8.GetBytes(sErrorBody); this.m_session.oResponse.headers = new HTTPResponseHeaders(KPCONFIG.oHeaderEncoding); this.m_session.oResponse.headers.HTTPResponseCode = iError; this.m_session.oResponse.headers.HTTPResponseStatus = iError.ToString() + " " + sErrorStatusText; this.m_session.oResponse.headers.Add("Content-Type", "text/html; charset=UTF-8"); this.m_session.oResponse.headers.Add("Connection", "close"); this.m_session.oResponse.headers.Add("Timestamp", DateTime.Now.ToString("HH:mm:ss.fff")); this.m_session.state = SessionStates.Aborted; KProxyApplication.DoBeforeReturningError(this.m_session); this.m_session.ReturnResponse(false); }
private void _indicateTunnelFailure(int iResponseCode, string sErr) { try { this._mySession.oResponse.headers = new HTTPResponseHeaders(); this._mySession.oResponse.headers.HTTPVersion = this._mySession.oRequest.headers.HTTPVersion; this._mySession.oResponse.headers.HTTPResponseCode = iResponseCode; this._mySession.oResponse.headers.HTTPResponseStatus = (iResponseCode == 0x1f6) ? "502 Gateway Connection failure" : "504 Connection Failed"; this._mySession.oResponse.headers.Add("Connection", "close"); this._mySession.responseBodyBytes = Encoding.UTF8.GetBytes("[Kavprot Proxy] " + this._mySession.oResponse.headers.HTTPResponseStatus + ": " + sErr + "<BR>Timestamp: " + DateTime.Now.ToString("HH:mm:ss.fff")); KProxyApplication.DoBeforeReturningError(this._mySession); this.socketClient.Send(this._mySession.oResponse.headers.ToByteArray(true, true)); this.socketClient.Send(this._mySession.responseBodyBytes); this.socketClient.Shutdown(SocketShutdown.Both); if (this.socketRemote != null) { this.socketRemote.Close(); } } catch { } }