Example #1
0
        internal void Flush(bool final_flush)
        {
            if (completed)
            {
                throw new HttpException("Server cannot flush a completed response");
            }

            DoFilter(final_flush);
            if (!headers_sent)
            {
                if (final_flush || status_code != 200)
                {
                    use_chunked = false;
                }
            }

            bool head = ((context != null) && (context.Request.HttpMethod == "HEAD"));

            if (suppress_content || head)
            {
                if (!headers_sent)
                {
                    WriteHeaders(true);
                }
                output_stream.Clear();
                if (WorkerRequest != null)
                {
                    output_stream.Flush(WorkerRequest, true);                      // ignore final_flush here.
                }
                completed = true;
                return;
            }
            completed = final_flush;

            if (!headers_sent)
            {
                WriteHeaders(final_flush);
            }

            if (context != null)
            {
                HttpApplication app_instance = context.ApplicationInstance;
                if (app_instance != null)
                {
                    app_instance.TriggerPreSendRequestContent();
                }
            }

            if (IsCached)
            {
                cached_response.SetData(output_stream.GetData());
            }

            if (WorkerRequest != null)
            {
                output_stream.Flush(WorkerRequest, final_flush);
            }
        }