System.Net.Http.Headers > HttpLimits

HttpLimits Class

public static class HttpLimits

Summary

Defines limits for HTTP protocol features.

Remarks

This class provides static properties to configure limits for various HTTP features within the .NET framework. These limits are often related to the maximum number of headers, body size, or other protocol-specific constraints to prevent abuse or resource exhaustion.

Understanding and adjusting these limits can be crucial for optimizing performance and ensuring the robustness of applications that heavily rely on HTTP communication.

Syntax

public static class HttpLimits

Members

MaxHeadersLength

public static HttpHeaderLimit? MaxHeadersLength { get; set; }

Gets or sets the maximum length of all HTTP headers combined.

This limit helps prevent denial-of-service attacks by restricting the total size of headers that can be sent or received.

MaxRequestContentBufferSize

public static long MaxRequestContentBufferSize { get; set; }

Gets or sets the maximum size of the request content buffer.

This property limits the amount of data that can be buffered for the request body. Setting this to a smaller value can help conserve memory for applications that handle large requests.

MaxResponseContentBufferSize

public static long MaxResponseContentBufferSize { get; set; }

Gets or sets the maximum size of the response content buffer.

Similar to MaxRequestContentBufferSize, this property limits the buffered data for response bodies. It's useful for controlling memory usage when processing potentially large responses.

Property Details

MaxHeadersLength

public static HttpHeaderLimit? MaxHeadersLength { get; set; }

Gets or sets the maximum length of all HTTP headers combined.

If the total size of HTTP headers exceeds this limit, an exception may be thrown. The default value is typically set to prevent excessive memory consumption and potential denial-of-service attacks.

Use this property to explicitly configure the header size limit for your application.

MaxRequestContentBufferSize

public static long MaxRequestContentBufferSize { get; set; }

Gets or sets the maximum size of the request content buffer.

This limit applies to the buffering of request body content. If the size of the request body exceeds this value, the behavior might be to truncate the content or throw an exception, depending on the specific implementation details and context. The default value is typically a reasonable size suitable for many common scenarios.

Adjust this value if you frequently send very large request bodies and want to control memory usage, or if you need to enforce stricter limits for security reasons.

MaxResponseContentBufferSize

public static long MaxResponseContentBufferSize { get; set; }

Gets or sets the maximum size of the response content buffer.

This property governs the maximum size of response body content that will be buffered. Exceeding this limit can result in exceptions or truncated data. The default value is configured to handle typical response sizes efficiently.

Consider modifying this setting if your application frequently receives extremely large responses and you need to manage memory usage effectively, or if you are implementing security measures against large data payloads.