Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

CA2262: Set 'MaxResponseHeadersLength' properly

  • 2024-02-21
Feedback

In this article

PropertyValue
Rule IDCA2262
TitleSetMaxResponseHeadersLength properly
CategoryUsage
Fix is breaking or non-breakingNon-breaking
Enabled by default in .NET 9As suggestion

Cause

TheHttpClientHandler.MaxResponseHeadersLength property is set to a value greater than 128.

Rule description

TheHttpClientHandler.MaxResponseHeadersLength property is measured in kilobytes, not bytes. The default maximum length is 64 KB, which should be large enough for a majority of use cases. If you set the property to a value greater than 128 kilobytes, it might be due to a misunderstanding of the units of this property.

How to fix violations

If you intended to set a smaller value, update it to the desired value measured in kilobytes.

Example

HttpClientHandler handler = new(){    // Violation    MaxResponseHeadersLength = 512    // Fix (it is not possible to specify a limit lower than 1 KB)    MaxResponseHeadersLength = 1};
Dim handler As New HttpClientHandler With {    ' Violation    .MaxResponseHeadersLength = 512    ' Fix (it is not possible to specify a limit lower than 1 KB)    .MaxResponseHeadersLength = 1}

When to suppress errors

It's safe to suppress this warning if the large value is intended.

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo