HttpAbstractions 343 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. commit 7b9da556fb7dc83d10e0ebd2ce1771a54935cd27
  2. Author: Doug Bunting <[email protected]>
  3. Date: Sat Jan 20 21:32:17 2018 -0800
  4. Add `HttpRequestRewindExtensions`
  5. - aspnet/Home#2684
  6. - makes the `BufferingHelper` methods used in MVC and WebHooks `public`
  7. diff --git a/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs b/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs
  8. new file mode 100644
  9. index 00000000000..557ee421550
  10. --- /dev/null
  11. +++ b/src/Microsoft.AspNetCore.Http/Extensions/HttpRequestRewindExtensions.cs
  12. @@ -0,0 +1,91 @@
  13. +// Copyright (c) .NET Foundation. All rights reserved.
  14. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  15. +
  16. +using Microsoft.AspNetCore.Http.Internal;
  17. +
  18. +namespace Microsoft.AspNetCore.Http
  19. +{
  20. + /// <summary>
  21. + /// Extension methods for enabling buffering in an <see cref="HttpRequest"/>.
  22. + /// </summary>
  23. + public static class HttpRequestRewindExtensions
  24. + {
  25. + /// <summary>
  26. + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
  27. + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
  28. + /// </summary>
  29. + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
  30. + /// <remarks>
  31. + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
  32. + /// environment variable, if any. If that environment variable is not defined, these files are written to the
  33. + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
  34. + /// </remarks>
  35. + public static void EnableBuffering(this HttpRequest request)
  36. + {
  37. + BufferingHelper.EnableRewind(request);
  38. + }
  39. +
  40. + /// <summary>
  41. + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
  42. + /// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
  43. + /// disk.
  44. + /// </summary>
  45. + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
  46. + /// <param name="bufferThreshold">
  47. + /// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
  48. + /// stream. Larger request bodies are written to disk.
  49. + /// </param>
  50. + /// <remarks>
  51. + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
  52. + /// environment variable, if any. If that environment variable is not defined, these files are written to the
  53. + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
  54. + /// </remarks>
  55. + public static void EnableBuffering(this HttpRequest request, int bufferThreshold)
  56. + {
  57. + BufferingHelper.EnableRewind(request, bufferThreshold);
  58. + }
  59. +
  60. + /// <summary>
  61. + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
  62. + /// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
  63. + /// </summary>
  64. + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
  65. + /// <param name="bufferLimit">
  66. + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
  67. + /// <see cref="System.IO.IOException"/>.
  68. + /// </param>
  69. + /// <remarks>
  70. + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
  71. + /// environment variable, if any. If that environment variable is not defined, these files are written to the
  72. + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
  73. + /// </remarks>
  74. + public static void EnableBuffering(this HttpRequest request, long bufferLimit)
  75. + {
  76. + BufferingHelper.EnableRewind(request, bufferLimit: bufferLimit);
  77. + }
  78. +
  79. + /// <summary>
  80. + /// Ensure the <paramref name="request"/> <see cref="HttpRequest.Body"/> can be read multiple times. Normally
  81. + /// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
  82. + /// disk.
  83. + /// </summary>
  84. + /// <param name="request">The <see cref="HttpRequest"/> to prepare.</param>
  85. + /// <param name="bufferThreshold">
  86. + /// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
  87. + /// stream. Larger request bodies are written to disk.
  88. + /// </param>
  89. + /// <param name="bufferLimit">
  90. + /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
  91. + /// <see cref="System.IO.IOException"/>.
  92. + /// </param>
  93. + /// <remarks>
  94. + /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
  95. + /// environment variable, if any. If that environment variable is not defined, these files are written to the
  96. + /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
  97. + /// </remarks>
  98. + public static void EnableBuffering(this HttpRequest request, int bufferThreshold, long bufferLimit)
  99. + {
  100. + BufferingHelper.EnableRewind(request, bufferThreshold, bufferLimit);
  101. + }
  102. + }
  103. +}