public void Write(char [] buffer, int offset, int count) { bool buffering = response.BufferOutput; if (buffering) { // It does not matter whether we're in ApplyFilter or not AppendBuffer(buffer, offset, count); } else if (filter == null || filtering) { response.WriteHeaders(false); HttpWorkerRequest wr = response.WorkerRequest; // Direct write because not buffering wr.SendResponseFromMemory(buffer, offset, count, response.ContentEncoding); wr.FlushResponse(false); } else { // Write to the filter, which will call us back, and then Flush filtering = true; try { byte [] bytesToWrite = response.ContentEncoding.GetBytes(buffer, offset, count); filter.Write(bytesToWrite, 0, bytesToWrite.Length); } finally { filtering = false; } Flush(response.WorkerRequest, false); } }