-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Adding IResult
implementation for FileStreamResult and LocalRedirectResult
#32956
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
Adding IResult
implementation for FileStreamResult and LocalRedirectResult
#32956
Conversation
IResult
implementation for FileStreamResult and LocalRedirectResult
throw new ArgumentNullException(nameof(httpContext)); | ||
} | ||
|
||
using (FileStream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, it is possible to share this implementation with the one in FileStreamExecutor (using an internal static method)? We could make the WriteFileAsync an optional parameter to the function to help with the overload.
static ExecuteAsync(HttpContext context, ILogger logger, Func<..., Task>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same q with the redirect result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea!, I will make the change on night :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pranavkm I take me more than I thought to get back into this, I have applied your suggestions, would you take a look?
async Task IResult.ExecuteAsync(HttpContext httpContext) | ||
{ | ||
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>(); | ||
var logger = loggerFactory.CreateLogger<RedirectResult>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is RedirectResult
the relevant type parameter for this logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should be FileStreamResult
, thanks! already fixed
d49cb15
to
1bf722e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in getting back
internal static async Task ExecuteAsyncInternal<TContext>( | ||
TContext context, | ||
FileStreamResult result, | ||
Func<TContext, FileStreamResult, long?, bool, DateTimeOffset?, EntityTagHeaderValue?, (RangeItemHeaderValue?, long, bool)> SetHeadersAndLog, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Func<TContext, FileStreamResult, long?, bool, DateTimeOffset?, EntityTagHeaderValue?, (RangeItemHeaderValue?, long, bool)> SetHeadersAndLog, | |
Func<TContext, FileStreamResult, long?, bool, DateTimeOffset?, EntityTagHeaderValue?, (RangeItemHeaderValue?, long, bool)> setHeadersAndLog, |
TContext context, | ||
FileStreamResult result, | ||
Func<TContext, FileStreamResult, long?, bool, DateTimeOffset?, EntityTagHeaderValue?, (RangeItemHeaderValue?, long, bool)> SetHeadersAndLog, | ||
Func<TContext, FileStreamResult, RangeItemHeaderValue?, long, Task> WriteFileAsync, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Func<TContext, FileStreamResult, RangeItemHeaderValue?, long, Task> WriteFileAsync, | |
Func<TContext, FileStreamResult, RangeItemHeaderValue?, long, Task> writeFileAsync, |
Task writeFileAsync(HttpContext httpContext, FileStreamResult result, RangeItemHeaderValue? range, long rangeLength) | ||
=> FileStreamResultExecutor.WriteFileAsyncInternal(httpContext, this, range, rangeLength, logger!); | ||
|
||
(RangeItemHeaderValue? range, long rangeLength, bool serveBody) setHeadersAndLog( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be
(RangeItemHeaderValue? range, long rangeLength, bool serveBody) setHeadersAndLog( | |
static (RangeItemHeaderValue? range, long rangeLength, bool serveBody) setHeadersAndLog( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(RangeItemHeaderValue? range, long rangeLength, bool serveBody) setHeadersAndLog( | |
(RangeItemHeaderValue? range, long rangeLength, bool serveBody) SetHeadersAndLog( |
var loggerFactory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>(); | ||
var logger = loggerFactory.CreateLogger<FileStreamResult>(); | ||
|
||
Task writeFileAsync(HttpContext httpContext, FileStreamResult result, RangeItemHeaderValue? range, long rangeLength) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Task writeFileAsync(HttpContext httpContext, FileStreamResult result, RangeItemHeaderValue? range, long rangeLength) | |
Task WriteFileAsync(HttpContext httpContext, FileStreamResult result, RangeItemHeaderValue? range, long rangeLength) |
setHeadersAndLog, | ||
writeFileAsync, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setHeadersAndLog, | |
writeFileAsync, | |
SetHeadersAndLog, | |
WriteFileAsync, |
ILogger logger | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ILogger logger | |
) | |
ILogger logger) |
@@ -45,36 +44,52 @@ public LocalRedirectResultExecutor(ILoggerFactory loggerFactory, IUrlHelperFacto | |||
/// <inheritdoc /> | |||
public virtual Task ExecuteAsync(ActionContext context, LocalRedirectResult result) | |||
{ | |||
if (context == null) | |||
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context); | |
if (context == null) | |
{ | |
throw new ArgumentNullException(nameof(context)); | |
} | |
var urlHelper = result.UrlHelper ?? _urlHelperFactory.GetUrlHelper(context); |
return ExecuteAsyncInternal( | ||
context.HttpContext, | ||
result, | ||
urlHelper.IsLocalUrl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a little iffy about this. This is now going to allocate a delegate per invocation. Could we have it fall-back in the implementation instead e.g.
internal static Task ExecuteAsyncInternal(
HttpContext httpContext,
LocalRedirectResult result,
IUrlHelper? urlHelper)
{
...
var isLocalUrl = urlHelper?.IsLocalUrl(url) ?? UrlHelperBase.CheckIsLocalUrl(url);
}
Thanks for your effort @barahonajm. We ended up deciding that it was best to avoid referencing MVC types from minimal actions especially for a common scenario such as the result types. We ended up duplicating the results and as such we no longer want to take this PR. Once again, thanks for your all your time! |
@pranavkm that sound like a right decision, thanks for your guidance during this time. See you in another PR :) |
Hi @barahonajm. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Summary
These changes add
IResult
implementation onActionResult
s that does not have itDetails
The
ActionResult
s that are going to be worked on this PR are:Task that needs to be done for this PR are:
Addresses part of #32565