src/packages/EmbedIO/HttpContextExtensions-ResponseStream.cs
/// <summary>
/// <para>Wraps the response output stream and returns a <see cref="Stream"/> that can be used directly.</para>
/// <para>Optional buffering is applied, so that the response may be sent as one (thereby properly setting the
/// <c>Content-Length</c> header) instead of using chunked transfer.</para>
/// <para>Proactive negotiation is performed to select the best compression method supported by the client.</para>
/// </summary>
/// <param name="this">The <see cref="IHttpContext"/> on which this method is called.</param>
/// <param name="buffered">If set to <see langword="true"/>, the data to send will be collected
/// in memory and sent all at once when the returned <see cref="Stream"/> is disposed,
/// setting the <c>Content-Length</c> response header;
/// if set to <see langword="false"/> (the default), chunked transfer will be used.</param>
/// <param name="preferCompression"><see langword="true"/> if sending compressed data is preferred over
/// sending non-compressed data; otherwise, <see langword="false"/>.</param>
/// <returns>
/// <para>A <see cref="Stream"/> that can be used to write response data.</para>
/// <para>This stream MUST be disposed when finished writing.</para>
/// </returns>
/// <seealso cref="OpenResponseText"/>
Wraps the response output stream and returns a  that can be used directly.Optional buffering is applied, so that the response may be sent as one (thereby properly setting the
Content-LengthProactive negotiation is performed to select the best compression method supported by the client.
Wraps the response output stream and returns a that can be used directly . Optional buffering is applied so that the response may be sent as one ( thereby properly setting the Content - LengthProactive negotiation is performed to select the best compression method supported by the client .
public static Stream OpenResponseStream(this IHttpContext @this, bool buffered = false, bool preferCompression = true)
        {
            @this.Request.TryNegotiateContentEncoding(preferCompression, out var compressionMethod, out var prepareResponse);
            prepareResponse(@this.Response); 
            var stream = buffered ? new BufferingResponseStream(@this.Response) : @this.Response.OutputStream;
            return compressionMethod switch {
                CompressionMethod.Gzip => new GZipStream(stream, CompressionMode.Compress),
                CompressionMethod.Deflate => new DeflateStream(stream, CompressionMode.Compress),
                _ => stream,
            };
        }
public static Stream OpenResponseStream ( this IHttpContext @this , bool buffered = false , bool preferCompression = true ) { @this . Request . TryNegotiateContentEncoding ( preferCompression , out var compressionMethod , out var prepareResponse ) ; prepareResponse ( @this . Response ) ; var stream = buffered ? new BufferingResponseStream ( @this . Response ) : @this . Response . OutputStream ; return compressionMethod switch { CompressionMethod . Gzip => new GZipStream ( stream , CompressionMode . Compress ) , CompressionMethod . Deflate => new DeflateStream ( stream , CompressionMode . Compress ) , _ => stream , } ; }
Wraps the response output stream and returns a  that can be used directly.Optional buffering is applied, so that the response may be sent as one (thereby properly setting the
Content-LengthProactive negotiation is performed to select the best compression method supported by the client.
Wraps the response output stream and returns a that can be used directly . Optional buffering is applied so that the response may be sent as one ( thereby properly setting the Content - LengthProactive negotiation is performed to select the best compression method supported by the client .
// The callback will throw HttpNotAcceptableException if negotiationSuccess is false.
A  that can be used to write response data.This stream MUST be disposed when finished writing.
A that can be used to write response data . This stream MUST be disposed when finished writing .
IHttpContext
this
buffered
bool
If set to , the data to send will be collected
in memory and sent all at once when the returned  is disposed,
setting the Content-Length (the default), chunked transfer will be used.
If set to the data to send will be collected in memory and sent all at once when the returned is disposed setting the Content - Length ( the default ) chunked transfer will be used .
preferCompression
bool
if sending compressed data is preferred over
sending non-compressed data; otherwise, .
if sending compressed data is preferred over sending non - compressed data ; otherwise .
this
The  on which this method is called.
The on which this method is called .
seealso
None