5.25Setting the Automatic Host Header

Updated on Aug 20, 2026~5 min read

The Host header is a required header in the HTTP/1.1 protocol. The Host header is used to specify the hostname and port number of the target server for a request, ensuring that the server can correctly distinguish between different domain names on the same IP address and handle them accordingly. The framework provides a simple way to configure this:

HTTP Declarative Requests set the automatic Host header through the AutoSetHostHeaderAttribute attribute. The corresponding HTTP declarative extractor is implemented as the AutoSetHostHeaderDeclarativeExtractor type, which is responsible for parsing the AutoSetHostHeaderAttribute attribute and building the automatic Host header configuration required by an HttpRequestBuilder instance.

cs
// Apply at the interface level to affect all methods[AutoSetHostHeader] // Enablepublic interface IHttpService : IHttpDeclarative{    // Apply at the method level    [AutoSetHostHeader]    [Get("https://furion.net/")]    Task<string> GetStringAsync();    [AutoSetHostHeader(false)]   // Disable the automatic Host header    [Get("https://furion.net/")]    Task<string> GetStringAsync();}

Once enabled, a Host: furion.net header is automatically added when sending HTTP remote requests.

AutoSetHostHeaderAttribute includes the following constructors and properties:

  • Constructors:

    • new(): Applies to methods or interfaces, setting the automatic Host header.
    • new(enabled): Applies to methods or interfaces, setting whether to set the automatic Host header.
  • Properties:

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