5.24Enabling Standard Request Headers

Updated on Aug 20, 2026~4 min read

To improve the compatibility of network requests sent by applications through the HTTP client and avoid being blocked by WAF (Web application firewalls), the framework provides a one-step configuration method that makes it easy to quickly set standard request headers uniformly.

HTTP Declarative Requests enable standard request headers through the StandardRequestHeadersAttribute attribute. The corresponding HTTP declarative extractor is implemented as the StandardRequestHeadersDeclarativeExtractor type, which is responsible for parsing the StandardRequestHeadersAttribute attribute and building the configuration required for an HttpRequestBuilder instance.

cs
// Applied at the interface level, affects all methods[StandardRequestHeaders]public interface IHttpService : IHttpDeclarative{    // Applied at the method level    [StandardRequestHeaders]    [Get("https://furion.net/")]    Task<string> GetStringAsync();    [StandardRequestHeaders(false)]   // Turn off standard request headers    [Get("https://furion.net/")]    Task<string> GetStringAsync();}

In addition to enabling standard header configuration for individual requests, you can also register it globally to enable it in HttpClient:

cs
// Enable for the default clientservices.AddHttpClient(string.Empty, client =>{    client.UseStandardRequestHeaders();});services.AddHttpRemote();

After standard request headers are enabled, requests automatically add the following headers:

  • Accept: application/json, text/plain;q=0.9, */*;q=0.8 (explicit media type priority to avoid being blocked by WAF)
  • Connection: Enables persistent connections (Keep-Alive) to reduce the overhead of establishing and closing TCP connections

StandardRequestHeadersAttribute contains the following constructors and properties:

  • Constructors:

    • new(): Applies to methods or interfaces and enables standard request headers.
    • new(enabled): Applies to methods or interfaces and sets whether to enable standard request headers.
  • Properties:

    • Enabled: Whether to enable (type bool), defaulting to true (enabled).