AnderssonPeter/CompressedStaticFiles

Feature request: "CompressedStaticFileResult"

judilsteve opened this issue · 4 comments

It would be fantastic to be able to call something like return CompressedStaticFileResult("some/file.html"); from a webapi controller method or return Results.CompressedStaticFile("some/file.html"); from a minimal API endpoint to leverage the conditional request and compressed file serving logic in custom endpoints. This would allow things like serving a 401/403 page with the appropriate status code.

I might be able to have a crack at this myself, I think it would look very similar to the CompressedStaticFileMiddleware class, except it would implement IActionResult and defer to PhysicalFileResult instead of StaticFileMiddleware. Would you consider accepting a PR?

I would be more than happy to look at any pull request you send my way, but I can't promise if I will accept it or not, it all depends on the quality.
If I don't accept I will give you some hints on what to do to get it accepted.

I'm not 100% sure but I think you would need to have some sort of service for this as you would have a hard time accessing configuration of CompressedStaticFiles in a static method or class?

Just a idea, haven't tried but what happens if you redirect instead? It might cause a extra roundtrip but should just work?

Ideally for my use case I'd like to do it within the request so that the user will see the URL of the page causing the error in their address bar, instead of some generic path like /403.html (which would be incongruently served with a 2xx response code). I suppose that option means giving up conditional request ability though (you can't respond to the same request with both 304 not modified and 403 forbidden at the same time).

I'll try drafting a PR when I can, but I work full time as a software dev so working on personal/OSS projects can often feel like working through the weekend.

I totally understand both your work time and not wanting a redirect, no rush from me if you manage to get time it's fine, if not it's also fine!