/// <summary> /// Writes a binary response asynchronous. /// </summary> /// <param name="context">The context.</param> /// <param name="file">The file.</param> /// <param name="contentType">Type of the content.</param> /// <param name="ct">The ct.</param> /// <param name="useGzip">if set to <c>true</c> [use gzip].</param> /// <returns> /// A task for writing the output stream. /// </returns> public static Task <bool> FileResponseAsync( this IHttpContext context, FileInfo file, string contentType = null, CancellationToken ct = default, bool useGzip = true) { context.Response.ContentType = contentType ?? Responses.HtmlContentType; using (var stream = file.OpenRead()) return(context.BinaryResponseAsync(stream, ct, useGzip)); }
/// <summary> /// Writes a binary response asynchronous. /// </summary> /// <param name="context">The context.</param> /// <param name="file">The file.</param> /// <param name="contentType">Type of the content.</param> /// <param name="useGzip">if set to <c>true</c> [use gzip].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A task for writing the output stream. /// </returns> public static Task <bool> FileResponseAsync( this IHttpContext context, FileInfo file, string contentType = null, bool useGzip = true, CancellationToken cancellationToken = default) { context.Response.ContentType = contentType ?? Responses.HtmlContentType; var stream = file.OpenRead(); return(context.BinaryResponseAsync(stream, useGzip, cancellationToken: cancellationToken)); }