-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: "CA2262: Set 'MaxResponseHeadersLength' properly" | ||
description: "Learn about code analysis rule CA2262 - Set 'MaxResponseHeadersLength' properly" | ||
ms.date: 01/30/2024 | ||
f1_keywords: | ||
- CA2262 | ||
helpviewer_keywords: | ||
- CA2262 | ||
dev_langs: | ||
- CSharp | ||
- VB | ||
--- | ||
# CA2262: Set 'MaxResponseHeadersLength' properly | ||
|
||
| Property | Value | | ||
|-------------------------------------|---------------------------------------------| | ||
| **Rule ID** | CA2262 | | ||
| **Title** | Set `MaxResponseHeadersLength` properly | | ||
| **Category** | [Usage](usage-warnings.md) | | ||
| **Fix is breaking or non-breaking** | Non-breaking | | ||
| **Enabled by default in .NET 9** | As suggestion | | ||
|
||
## Cause | ||
|
||
The <xref:System.Net.Http.HttpClientHandler.MaxResponseHeadersLength?displayProperty=nameWithType> property is set to a value greater than 128. | ||
|
||
## Rule description | ||
|
||
The <xref:System.Net.Http.HttpClientHandler.MaxResponseHeadersLength?displayProperty=nameWithType> 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 the desired value measured in kilobytes. | ||
|
||
## Example | ||
|
||
```csharp | ||
HttpClientHandler handler = new() | ||
{ | ||
// Violation | ||
MaxResponseHeadersLength = 512 | ||
|
||
// Fix | ||
MaxResponseHeadersLength = 0.512 | ||
}; | ||
``` | ||
|
||
```vb | ||
|
||
Dim handler As New HttpClientHandler With { | ||
' Violation | ||
.MaxResponseHeadersLength = 512 | ||
|
||
' Fix | ||
.MaxResponseHeadersLength = 0.512 | ||
} | ||
``` | ||
|
||
## When to suppress errors | ||
|
||
It's safe to suppress this warning if the large value is intended. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters