Skip to content

Commit

Permalink
Add AllowAutoRedirect option on HttpClientFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocontrini committed Dec 19, 2024
1 parent c0b8b90 commit 8b8f3ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions PlainHttp/HttpClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public record HttpHandlerOptions
/// Whether to ignore certificate validation errors. Default: false.
/// </summary>
public bool IgnoreCertificateValidationErrors { get; init; }

/// <summary>
/// Whether redirect responses should be automatically followed. Default: true.
/// </summary>
public bool AllowAutoRedirect { get; set; } = true;
}

public HttpClientFactory()
Expand Down Expand Up @@ -119,7 +124,8 @@ protected virtual HttpClient CreateClient()
this.handlerOptions.EnabledSslProtocols,
this.handlerOptions.IgnoreCertificateValidationErrors
),
ConnectTimeout = this.handlerOptions.ConnectTimeout
ConnectTimeout = this.handlerOptions.ConnectTimeout,
AllowAutoRedirect = this.handlerOptions.AllowAutoRedirect,
};

HttpClient client = new HttpClient(handler)
Expand Down Expand Up @@ -152,7 +158,8 @@ protected virtual HttpClient CreateProxiedClient(Uri proxyUrl)
this.proxyHandlerOptions.EnabledSslProtocols,
this.proxyHandlerOptions.IgnoreCertificateValidationErrors
),
ConnectTimeout = this.proxyHandlerOptions.ConnectTimeout
ConnectTimeout = this.proxyHandlerOptions.ConnectTimeout,
AllowAutoRedirect = this.proxyHandlerOptions.AllowAutoRedirect,
};

HttpClient client = new HttpClient(handler)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public record HttpHandlerOptions
public DecompressionMethods AutomaticDecompression { get; init; } = DecompressionMethods.All;
public SslProtocols EnabledSslProtocols { get; init; } = SslProtocols.None;
public bool IgnoreCertificateValidationErrors { get; init; }
public bool AllowAutoRedirect { get; set; } = true;
}
```

Expand All @@ -495,6 +496,7 @@ The meanings of these options (which usually map to `SocketsHttpHandler` propert
- `AutomaticDecompression`: the decompression methods to use for the response body. By default, all methods (gzip, DEFLATE and Brotli) are enabled.
- `EnabledSslProtocols`: the SSL/TLS protocols to use. By default, the system default is used.
- `IgnoreCertificateValidationErrors`: whether to ignore certificate validation errors.
- `AllowAutoRedirect`: whether redirect responses should be automatically followed. By default, redirects are followed.

Note that when applied to proxied clients these options will apply to the connection to the proxy server itself.

Expand Down

0 comments on commit 8b8f3ec

Please sign in to comment.