diff --git a/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs b/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs new file mode 100644 index 0000000000..557ee42155 --- /dev/null +++ b/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs @@ -0,0 +1,91 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Http.Internal; + +namespace Microsoft.AspNetCore.Http +{ + /// + /// Extension methods for enabling buffering in an . + /// + public static class HttpRequestRewindExtensions + { + /// + /// Ensure the can be read multiple times. Normally + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk. + /// + /// The to prepare. + /// + /// Temporary files for larger requests are written to the location named in the ASPNETCORE_TEMP + /// environment variable, if any. If that environment variable is not defined, these files are written to the + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests. + /// + public static void EnableBuffering(this HttpRequest request) + { + BufferingHelper.EnableRewind(request); + } + + /// + /// Ensure the can be read multiple times. Normally + /// buffers request bodies in memory; writes requests larger than bytes to + /// disk. + /// + /// The to prepare. + /// + /// The maximum size in bytes of the in-memory used to buffer the + /// stream. Larger request bodies are written to disk. + /// + /// + /// Temporary files for larger requests are written to the location named in the ASPNETCORE_TEMP + /// environment variable, if any. If that environment variable is not defined, these files are written to the + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests. + /// + public static void EnableBuffering(this HttpRequest request, int bufferThreshold) + { + BufferingHelper.EnableRewind(request, bufferThreshold); + } + + /// + /// Ensure the can be read multiple times. Normally + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk. + /// + /// The to prepare. + /// + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an + /// . + /// + /// + /// Temporary files for larger requests are written to the location named in the ASPNETCORE_TEMP + /// environment variable, if any. If that environment variable is not defined, these files are written to the + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests. + /// + public static void EnableBuffering(this HttpRequest request, long bufferLimit) + { + BufferingHelper.EnableRewind(request, bufferLimit: bufferLimit); + } + + /// + /// Ensure the can be read multiple times. Normally + /// buffers request bodies in memory; writes requests larger than bytes to + /// disk. + /// + /// The to prepare. + /// + /// The maximum size in bytes of the in-memory used to buffer the + /// stream. Larger request bodies are written to disk. + /// + /// + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an + /// . + /// + /// + /// Temporary files for larger requests are written to the location named in the ASPNETCORE_TEMP + /// environment variable, if any. If that environment variable is not defined, these files are written to the + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests. + /// + public static void EnableBuffering(this HttpRequest request, int bufferThreshold, long bufferLimit) + { + BufferingHelper.EnableRewind(request, bufferThreshold, bufferLimit); + } + } +}