diff options
| author | Stefan Boberg <[email protected]> | 2026-04-20 10:58:35 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-04-20 10:58:35 +0200 |
| commit | 71cce4951b7e132c3aff5eb4cbe2985aca527e46 (patch) | |
| tree | 5c99d9462f4b78726a0e6193bc78002049c57760 /src | |
| parent | Move ZipFs from zenserver frontend into zenhttp (#980) (diff) | |
| download | archived-zen-71cce4951b7e132c3aff5eb4cbe2985aca527e46.tar.xz archived-zen-71cce4951b7e132c3aff5eb4cbe2985aca527e46.zip | |
zenhttp: add FollowRedirects option to HttpClient (#982)
- Adds `FollowRedirects` (default `false`) and `MaxRedirects` (default `5`) fields to `HttpClientSettings`.
- When `FollowRedirects` is enabled, the curl backend sets `CURLOPT_FOLLOWLOCATION` and `CURLOPT_MAXREDIRS` so HTTP 3xx redirects are handled transparently in the transport layer — callers no longer need to parse `Location` headers and re-issue requests themselves.
- Defaults are off, so existing callers see no behavior change.
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenhttp/clients/httpclientcurl.cpp | 6 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpclient.h | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/zenhttp/clients/httpclientcurl.cpp b/src/zenhttp/clients/httpclientcurl.cpp index 3be7337c1..ddf6cb58f 100644 --- a/src/zenhttp/clients/httpclientcurl.cpp +++ b/src/zenhttp/clients/httpclientcurl.cpp @@ -607,6 +607,12 @@ CurlHttpClient::AllocSession(std::string_view ResourcePath, const KeyValueMap& P // Disable signal handling for thread safety curl_easy_setopt(Handle, CURLOPT_NOSIGNAL, 1L); + if (m_ConnectionSettings.FollowRedirects) + { + curl_easy_setopt(Handle, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(Handle, CURLOPT_MAXREDIRS, static_cast<long>(m_ConnectionSettings.MaxRedirects)); + } + if (m_ConnectionSettings.ForbidReuseConnection) { curl_easy_setopt(Handle, CURLOPT_FORBID_REUSE, 1L); diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h index e199b700f..8da94524e 100644 --- a/src/zenhttp/include/zenhttp/httpclient.h +++ b/src/zenhttp/include/zenhttp/httpclient.h @@ -120,6 +120,13 @@ struct HttpClientSettings /// the system default CA store. std::string CaBundlePath; + /// Automatically follow HTTP 3xx redirects. When true, curl handles + /// redirects internally (up to MaxRedirects hops). Default: false. + bool FollowRedirects = false; + + /// Maximum number of redirects to follow when FollowRedirects is true. + int MaxRedirects = 5; + /// HTTP status codes that are expected and should not be logged as warnings. /// 404 is always treated as expected regardless of this list. std::vector<HttpResponseCode> ExpectedErrorCodes; |