| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- commit 7b9da556fb7dc83d10e0ebd2ce1771a54935cd27
- Author: Doug Bunting <[email protected]>
- Date: Sat Jan 20 21:32:17 2018 -0800
- Add `HttpRequestRewindExtensions`
- - aspnet/Home#2684
- - makes the `BufferingHelper` methods used in MVC and WebHooks `public`
- diff --git a/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs b/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs
- new file mode 100644
- index 00000000000..557ee421550
- --- /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
- +{
- + /// <summary>
- + /// Extension methods for enabling buffering in an <see cref="HttpRequest"/>.
- + /// </summary>
- + public static class HttpRequestRewindExtensions
- + {
- + /// <summary>
- + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
- + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
- + /// </summary>
- + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
- + /// <remarks>
- + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
- + /// 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.
- + /// </remarks>
- + public static void EnableBuffering(this HttpRequest request)
- + {
- + BufferingHelper.EnableRewind(request);
- + }
- +
- + /// <summary>
- + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
- + /// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
- + /// disk.
- + /// </summary>
- + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
- + /// <param name="bufferThreshold">
- + /// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
- + /// stream. Larger request bodies are written to disk.
- + /// </param>
- + /// <remarks>
- + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
- + /// 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.
- + /// </remarks>
- + public static void EnableBuffering(this HttpRequest request, int bufferThreshold)
- + {
- + BufferingHelper.EnableRewind(request, bufferThreshold);
- + }
- +
- + /// <summary>
- + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
- + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
- + /// </summary>
- + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
- + /// <param name="bufferLimit">
- + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
- + /// <see cref="System.IO.IOException"/>.
- + /// </param>
- + /// <remarks>
- + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
- + /// 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.
- + /// </remarks>
- + public static void EnableBuffering(this HttpRequest request, long bufferLimit)
- + {
- + BufferingHelper.EnableRewind(request, bufferLimit: bufferLimit);
- + }
- +
- + /// <summary>
- + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
- + /// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
- + /// disk.
- + /// </summary>
- + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
- + /// <param name="bufferThreshold">
- + /// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
- + /// stream. Larger request bodies are written to disk.
- + /// </param>
- + /// <param name="bufferLimit">
- + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
- + /// <see cref="System.IO.IOException"/>.
- + /// </param>
- + /// <remarks>
- + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
- + /// 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.
- + /// </remarks>
- + public static void EnableBuffering(this HttpRequest request, int bufferThreshold, long bufferLimit)
- + {
- + BufferingHelper.EnableRewind(request, bufferThreshold, bufferLimit);
- + }
- + }
- +}
|