Example #1
0
        /// <summary>
        /// Sets etag and last modified headers.
        /// </summary>
        /// <param name="context">The <see cref="ActionContext"/>.</param>
        /// <param name="result">The <see cref="FileResult"/>.</param>
        /// <param name="fileLength">The nullable file length.</param>
        /// <param name="enableRangeProcessing">Whether range processing is enabled.</param>
        /// <param name="lastModified">The nullable lastModified date.</param>
        /// <param name="etag">The <see cref="EntityTagHeaderValue"/>.</param>
        /// <returns>A tuple with the <see cref="RangeItemHeaderValue"/> range, length, and whether the body was served.</returns>
        protected virtual (RangeItemHeaderValue?range, long rangeLength, bool serveBody) SetHeadersAndLog(
            ActionContext context,
            FileResult result,
            long?fileLength,
            bool enableRangeProcessing,
            DateTimeOffset?lastModified = null,
            EntityTagHeaderValue?etag   = null)
        {
            var fileResultInfo = new FileResultInfo
            {
                ContentType           = result.ContentType,
                EnableRangeProcessing = result.EnableRangeProcessing,
                EntityTag             = result.EntityTag,
                FileDownloadName      = result.FileDownloadName,
                LastModified          = result.LastModified,
            };

            return(FileResultHelper.SetHeadersAndLog(context.HttpContext, fileResultInfo, fileLength, enableRangeProcessing, lastModified, etag, Logger));
        }
Example #2
0
    public virtual Task ExecuteAsync(HttpContext httpContext)
    {
        var logger = GetLogger(httpContext);

        Log.ExecutingFileResult(logger, this);

        var fileResultInfo = new FileResultInfo
        {
            ContentType           = ContentType,
            EnableRangeProcessing = EnableRangeProcessing,
            EntityTag             = EntityTag,
            FileDownloadName      = FileDownloadName,
            LastModified          = LastModified,
        };

        var(range, rangeLength, serveBody) = FileResultHelper.SetHeadersAndLog(
            httpContext,
            fileResultInfo,
            FileLength,
            EnableRangeProcessing,
            LastModified,
            EntityTag,
            logger);

        if (!serveBody)
        {
            return(Task.CompletedTask);
        }

        if (range != null && rangeLength == 0)
        {
            return(Task.CompletedTask);
        }

        if (range != null)
        {
            FileResultHelper.Log.WritingRangeToBody(logger);
        }

        return(ExecuteCoreAsync(httpContext, range, rangeLength));
    }