Skip to content

Request buffering #20001

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

Open
Tratcher opened this issue Sep 25, 2020 · 1 comment
Open

Request buffering #20001

Tratcher opened this issue Sep 25, 2020 · 1 comment
Labels
code help wanted Sample code help wanted. doc-idea Pri---0.5 Don't delete without permission

Comments

@Tratcher
Copy link
Member

Describe the new topic

  • Explain why this topic is needed.

It's not uncommon for apps to buffer the request body in order to do secondary processing, logging, etc..

  • Suggest a location in the Table of Contents.

Under Advanced?

  • Write an abstract. In one short paragraph, describe what this topic will cover.

Request bodies are streamed by default, meaning only one component gets a chance to read it. If that component wants to preserve the original data for later components in the pipeline it needs buffer the full request body. The HttpRequest.EnableBuffering API can help with this.

  • Create an outline for the new topic. We'll help review the outline and approve it before anyone writes a topic.

Why buffer - For replay
When to avoid buffering - Very large content,
Where does the buffer go - X amount in memory, and then to a temp file on disk that's deleted at the end of the request.
Affects on request body size limits - The server enforces a request body size limit that defaults to ~30mb. This can be overridden per request using the IHttpMaxRequestBodySizeFeature. MVC controllers may use an attribute to override this, but if you buffer the body too soon then that may not have happened yet.
An example middleware

context.Request.EnableBuffering();
await context.Request.Body.DrainAsync(); // Or your own processing that reads the body.
context.Request.Body.Position = 0;
await next();

See comments starting at dotnet/aspnetcore#7644 (comment) and continuing at least through 9/24/20.

@Rick-Anderson
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code help wanted Sample code help wanted. doc-idea Pri---0.5 Don't delete without permission
Projects
None yet
Development

No branches or pull requests

3 participants