title: FiddlerCore session timeout
body: <p>I'm handling local requests by using FiddlerCore. All sessions are queued in <code>Queue&lt;Session&gt;</code> and processed by a <code>BackgroundWorker</code>. After the process is done, I would like to send a response, indicating the success or failure of the processing, by using the processed session. The problem is that I'm getting the <strong>Too late, we're already talking to the server</strong> error.</p>
  
  <p>This is the FiddlerCore function:</p>
  
  <pre><code>private static void FiddlerApplication_BeforeRequest(Session session)
  {
      if (session.hostname.ToLower() == "localhost")
      {
          LogHelper.WriteFormat("Local request {0} enqueued", session.id);
          sessionsQueue.Enqueue(session);
  
          if (!sessionWorker.IsBusy)
              sessionWorker.RunWorkerAsync();
      }
  }
  </code></pre>
  
  <p>This is the thread function:</p>
  
  <pre><code>private static void sessionWorker_DoWork(object sender, DoWorkEventArgs e)
  {
      while (sessionsQueue.Count &gt; 0)
      {
          if (sessionWorker.CancellationPending)
          {
              e.Cancel = true;
              sessionsQueue.Clear();
              LogHelper.Write("Shutting down, all requests canceled");
              break;
          }
  
          currentSession = sessionsQueue.Dequeue();
          LogHelper.WriteFormat("Processing request ID {0}", currentSession.id);
          ProcessSession();
      }
  }
  </code></pre>
  
  <p>This is the code at the end of the <code>ProcessSession</code> function:</p>
  
  <pre><code>{
  ...        
      currentSession.bBufferResponse = true;
      currentSession.utilCreateResponseAndBypassServer();
      currentSession.oResponse.headers.HTTPResponseStatus = "200 OK";
      currentSession.oResponse["Content-Type"] = "text/html; charset=UTF-8";
      currentSession.oResponse["Cache-Control"] = "private, max-age=0";
      currentSession.utilSetResponseBody(responseBody);
  }
  </code></pre>
  
  <p>I've tried to tamper with the session's timers and state, but without success.</p>