diff --git a/src/Mvc/Mvc.NewtonsoftJson/src/MvcNewtonsoftJsonOptions.cs b/src/Mvc/Mvc.NewtonsoftJson/src/MvcNewtonsoftJsonOptions.cs index 19e459b4c0..05bc55b20a 100644 --- a/src/Mvc/Mvc.NewtonsoftJson/src/MvcNewtonsoftJsonOptions.cs +++ b/src/Mvc/Mvc.NewtonsoftJson/src/MvcNewtonsoftJsonOptions.cs @@ -39,6 +39,16 @@ namespace Microsoft.AspNetCore.Mvc /// public JsonSerializerSettings SerializerSettings { get; } = JsonSerializerSettingsProvider.CreateSerializerSettings(); + /// + /// Gets the maximum size to buffer in memory when is not set. + /// + /// buffers the input stream by default, buffering up to a certain amount in memory, before buffering to disk. + /// This option configures the size in bytes that MVC will buffer in memory, before switching to disk. + /// + /// + /// Defaults to 30Kb. + public int InputFormatterMemoryBufferThreshold { get; set; } = 1024 * 30; + IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator(); diff --git a/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs b/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs index 3528916b3e..9dcce51665 100644 --- a/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs +++ b/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class NewtonsoftJsonInputFormatter : TextInputFormatter, IInputFormatterExceptionPolicy { - private const int DefaultMemoryThreshold = 1024 * 30; private readonly IArrayPool _charPool; private readonly ILogger _logger; private readonly ObjectPoolProvider _objectPoolProvider; @@ -144,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { // JSON.Net does synchronous reads. In order to avoid blocking on the stream, we asynchronously // read everything into a buffer, and then seek back to the beginning. - var memoryThreshold = DefaultMemoryThreshold; + var memoryThreshold = _jsonOptions.InputFormatterMemoryBufferThreshold; var contentLength = request.ContentLength.GetValueOrDefault(); if (contentLength > 0 && contentLength < memoryThreshold) {