public override Stream GetOutputStream(bool disableCompression = false) { bool gzipEnable = false; if (!m_IsHeaderSent) { Headers.Remove("Content-Length"); if (!disableCompression && AcceptedEncodings != null && AcceptedEncodings.Contains("gzip")) { gzipEnable = true; Headers["Content-Encoding"] = "gzip"; } SendHeaders(); } else { throw new InvalidOperationException(); } Stream stream = m_Output; if (gzipEnable) { stream = new GZipStream(stream, CompressionMode.Compress); } m_Output = null; return(stream); }
public override Stream GetOutputStream(bool disableCompression = false) { bool gzipEnable = false; if (!m_IsHeaderSent) { if (!IsChunkedAccepted) { IsCloseConnection = true; } Headers.Remove("Content-Length"); if (!disableCompression && AcceptedEncodings != null && AcceptedEncodings.Contains("gzip")) { gzipEnable = true; Headers["Content-Encoding"] = "gzip"; } if (IsChunkedAccepted) { Headers["Transfer-Encoding"] = "chunked"; } else { Headers["Connection"] = "close"; } SendHeaders(); } else { throw new InvalidOperationException(); } Stream stream; if (IsChunkedAccepted) { stream = new HttpWriteChunkedBodyStream(m_Output); } else { stream = new HttpResponseBodyStream(m_Output); } /* we never give out the original stream because Close is working recursively according to .NET specs */ if (gzipEnable) { stream = new GZipStream(stream, CompressionMode.Compress); } return(stream); }