dotnet / dotnet/aspnetcore

Support returning Stream and PipeReader directly from route handler methods

Open
#39,711 2 comments 2 reactions 0 assignees View on GitHub
area-minimal
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.