Support returning Stream and PipeReader directly from route handler methods
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
Today we support several built in types as result types (along with async versions), `string`, `IResult`, any other object (JSON). The idea is to extend support for `Stream` and `PipeReader` (along with the async versions). This provides symmetry with automatic binding of Stream and PipeReader in the input and as the built in version of https://github.com/dotnet/aspnetcore/issues/39383.
### Describe the solution you'd like
This is an extension of https://github.com/dotnet/aspnetcore/issues/39383 to natively understand `Stream`, `Task`, `ValueTask`, `PipeReader`, `Task`, and `ValueTask` as a return type from handler methods. The default behavior would be:
- Set the content type to "application/octet-stream" (if it's not already set)
- We always copy the entire stream to the response body
- Does not support range requests
- Does not support download file names
### Additional context
```C#
app.MapGet("/blob/download1", () =>
{
return File.OpenRead("../something.txt");
});
```
Contributor guide
Assessment
This issue has not been assessed yet.