Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 7b9da55

Browse files
committed
Add HttpRequestRewindExtensions
- dotnet/aspnetcore#2684 - makes the `BufferingHelper` methods used in MVC and WebHooks `public`
1 parent 816ecf5 commit 7b9da55

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http.Internal;
5+
6+
namespace Microsoft.AspNetCore.Http
7+
{
8+
/// <summary>
9+
/// Extension methods for enabling buffering in an <see cref="HttpRequest"/>.
10+
/// </summary>
11+
public static class HttpRequestRewindExtensions
12+
{
13+
/// <summary>
14+
/// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
15+
/// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
16+
/// </summary>
17+
/// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
18+
/// <remarks>
19+
/// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
20+
/// environment variable, if any. If that environment variable is not defined, these files are written to the
21+
/// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
22+
/// </remarks>
23+
public static void EnableBuffering(this HttpRequest request)
24+
{
25+
BufferingHelper.EnableRewind(request);
26+
}
27+
28+
/// <summary>
29+
/// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
30+
/// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
31+
/// disk.
32+
/// </summary>
33+
/// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
34+
/// <param name="bufferThreshold">
35+
/// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
36+
/// stream. Larger request bodies are written to disk.
37+
/// </param>
38+
/// <remarks>
39+
/// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
40+
/// environment variable, if any. If that environment variable is not defined, these files are written to the
41+
/// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
42+
/// </remarks>
43+
public static void EnableBuffering(this HttpRequest request, int bufferThreshold)
44+
{
45+
BufferingHelper.EnableRewind(request, bufferThreshold);
46+
}
47+
48+
/// <summary>
49+
/// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
50+
/// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
51+
/// </summary>
52+
/// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
53+
/// <param name="bufferLimit">
54+
/// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
55+
/// <see cref="System.IO.IOException"/>.
56+
/// </param>
57+
/// <remarks>
58+
/// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
59+
/// environment variable, if any. If that environment variable is not defined, these files are written to the
60+
/// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
61+
/// </remarks>
62+
public static void EnableBuffering(this HttpRequest request, long bufferLimit)
63+
{
64+
BufferingHelper.EnableRewind(request, bufferLimit: bufferLimit);
65+
}
66+
67+
/// <summary>
68+
/// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
69+
/// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
70+
/// disk.
71+
/// </summary>
72+
/// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
73+
/// <param name="bufferThreshold">
74+
/// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
75+
/// stream. Larger request bodies are written to disk.
76+
/// </param>
77+
/// <param name="bufferLimit">
78+
/// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
79+
/// <see cref="System.IO.IOException"/>.
80+
/// </param>
81+
/// <remarks>
82+
/// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
83+
/// environment variable, if any. If that environment variable is not defined, these files are written to the
84+
/// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
85+
/// </remarks>
86+
public static void EnableBuffering(this HttpRequest request, int bufferThreshold, long bufferLimit)
87+
{
88+
BufferingHelper.EnableRewind(request, bufferThreshold, bufferLimit);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)