public void FailSession(int iError, string sErrorStatusText, string sErrorBody) { this.m_session.SetBitFlag(SessionFlags.ResponseGeneratedByFiddler, 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(CONFIG.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; FiddlerApplication.DoBeforeReturningError(this.m_session); this.m_session.ReturnResponse(false); }
internal void BuildAndReturnResponse(int iStatus, string sStatusText, string sBodyText, Action <Session> delLastChance) { this.m_session.SetBitFlag(SessionFlags.ResponseGeneratedByFiddler, true); if (iStatus >= 400 && sBodyText.Length < 512) { sBodyText = sBodyText.PadRight(512, ' '); } this.m_session.responseBodyBytes = Encoding.UTF8.GetBytes(sBodyText); this.m_session.oResponse.headers = new HTTPResponseHeaders(CONFIG.oHeaderEncoding); this.m_session.oResponse.headers.SetStatus(iStatus, sStatusText); this.m_session.oResponse.headers.Add("Date", DateTime.Now.ToUniversalTime().ToString("r")); 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; if (delLastChance != null) { delLastChance(this.m_session); } FiddlerApplication.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("[Fiddler] " + this._mySession.oResponse.headers.HTTPResponseStatus + ": " + sErr + "<BR>Timestamp: " + DateTime.Now.ToString("HH:mm:ss.fff")); FiddlerApplication.DoBeforeReturningError(this._mySession); FiddlerApplication._frmMain.BeginInvoke(new updateUIDelegate(FiddlerApplication._frmMain.finishSession), new object[] { 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 (Exception) { } }