Skip to content

Add IResult implementation for FileResult #32835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

wcontayon
Copy link
Contributor

Summary
These changes add necessary implementation to FileResult

Details

  • Basic implementation for FileResult
  • [ ] Add/Update test suite to test the FileResult ExecuteResultAsync

Addresses #32565

@ghost ghost added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member labels May 19, 2021
@dnfadmin
Copy link

dnfadmin commented May 19, 2021

CLA assistant check
All CLA requirements met.

@wcontayon
Copy link
Contributor Author

Hi @davidfowl, @halter73 this is a draft of the PR.
Some changes have all ready done with #32647 (specially for the FileResultExecutorBase).
Please do not hesitate to put your comments

@davidfowl
Copy link
Member

I think we have a clash 😢 #32647

@wcontayon
Copy link
Contributor Author

wcontayon commented May 19, 2021

I think we have a clash 😢 #32647

I noticed the implementation on other FileResult inherited classes 😅 on the PR #32647 .
@davidfowl, @halter73 is that a good idea to inherit both FileResult and children classes from IResult ?
I could revert these changes and implement the interface on other ActionResult as needed.

logger.WritingRangeToBody();
}

return FileResultExecutorBase.WriteFileAsync(httpContext, httpContext.Response.Body, range, rangeLenth);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that FileResultExecutorBase.WriteFileAsync expects a fileStream as the second argument. It can get the Response.Body from the HttpContext, but I don't think we have the actual fileStream in the FileResult base class.

Thanks for taking the time to help out and submit this PR! Unfortunately, this does conflict with #32647, and I think we're going to end up merging that first.

Copy link
Contributor Author

@wcontayon wcontayon May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @halter73.
Looking forward what have been achieved on this PR #32647 :), and take other ActionResult based on 32565

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. It's too bad we can't take both contributions.

I think it might be best to look for other help-wanted issues because it sounds like @barahonajm also looking to do more of these.

SetContentType(context.HttpContext, result);
}

internal static void SetContentType(HttpContext httpContext, FileResult result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need a separate method for a one-liner?

response.ContentType = result.ContentType;
}

private static void SetContentDispositionHeader(ActionContext context, FileResult result)
{
SetContentDispositionHeader(context.HttpContext, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the calling code to pass the HttpContext instead? Seems like overkill to have a one-liner like this.

bool enableRangeProcessing,
DateTimeOffset? lastModified = null,
EntityTagHeaderValue? etag = null,
ILogger? logger = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this null?

fileLength);

// Overwrite the Content-Length header for valid range requests with the range length.
var rangeLength = SetContentLength(response, range);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass in the ILogger.

RequestHeaders httpRequestHeaders,
DateTimeOffset? lastModified,
EntityTagHeaderValue? etag)
EntityTagHeaderValue? etag,
ILogger? logger = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be non-nullable / non-optional.

@@ -363,6 +394,54 @@ private static PreconditionState GetMaxPreconditionState(params PreconditionStat
return (range, rangeLength, serveBody);
}

internal static (RangeItemHeaderValue? range, long rangeLength, bool serveBody) SetRangeHeaders(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you unable to re-use the existing SetRangeHeaders method?

@halter73
Copy link
Member

I talked to @pranavkm offline. We're going to try to merge #32647 instead. Thanks again!

@halter73 halter73 closed this May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants