From c0ff6f9a3c942db261fb5cd78dc151ea394ee389 Mon Sep 17 00:00:00 2001 From: ptahmose Date: Thu, 16 Nov 2023 11:25:41 +0100 Subject: [PATCH] add option "kCurlHttp_FollowLocation" (#79) * add option "kCurlHttp_FollowLocation" * bump version * add accidentally removed option --- CMakeLists.txt | 2 +- Src/CZICmd/cmdlineoptions.cpp | 2 ++ Src/libCZI/StreamsLib/curlhttpinputstream.cpp | 14 ++++++++++++++ Src/libCZI/libCZI_StreamsLib.h | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ede42bb..9a38f936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html) project(libCZI - VERSION 0.54.2 + VERSION 0.54.3 HOMEPAGE_URL "https://github.com/ZEISS/libczi" DESCRIPTION "libCZI is an Open Source Cross-Platform C++ library to read and write CZI") diff --git a/Src/CZICmd/cmdlineoptions.cpp b/Src/CZICmd/cmdlineoptions.cpp index 193a306a..6b229062 100644 --- a/Src/CZICmd/cmdlineoptions.cpp +++ b/Src/CZICmd/cmdlineoptions.cpp @@ -2194,6 +2194,8 @@ void CCmdLineOptions::PrintHelpStreamsObjects() {"CurlHttp_Cookie", libCZI::StreamsFactory::StreamProperties::kCurlHttp_Cookie, libCZI::StreamsFactory::Property::Type::String}, {"CurlHttp_SslVerifyPeer", libCZI::StreamsFactory::StreamProperties::kCurlHttp_SslVerifyPeer, libCZI::StreamsFactory::Property::Type::Boolean}, {"CurlHttp_SslVerifyHost", libCZI::StreamsFactory::StreamProperties::kCurlHttp_SslVerifyHost, libCZI::StreamsFactory::Property::Type::Boolean}, + {"CurlHttp_FollowLocation", libCZI::StreamsFactory::StreamProperties::kCurlHttp_FollowLocation, libCZI::StreamsFactory::Property::Type::Boolean}, + {"CurlHttp_MaxRedirs", libCZI::StreamsFactory::StreamProperties::kCurlHttp_MaxRedirs, libCZI::StreamsFactory::Property::Type::Int32}, }; rapidjson::Document document; diff --git a/Src/libCZI/StreamsLib/curlhttpinputstream.cpp b/Src/libCZI/StreamsLib/curlhttpinputstream.cpp index 2a402791..84be504f 100644 --- a/Src/libCZI/StreamsLib/curlhttpinputstream.cpp +++ b/Src/libCZI/StreamsLib/curlhttpinputstream.cpp @@ -166,6 +166,20 @@ CurlHttpInputStream::CurlHttpInputStream(const std::string& url, const std::map< ThrowIfCurlSetOptError(return_code, "CURLOPT_SSL_VERIFYHOST"); } + property = property_bag.find(StreamsFactory::StreamProperties::kCurlHttp_FollowLocation); + if (property != property_bag.end()) + { + return_code = curl_easy_setopt(up_curl_handle.get(), CURLOPT_FOLLOWLOCATION, property->second.GetAsBoolOrThrow() ? 1L : 0L); + ThrowIfCurlSetOptError(return_code, "CURLOPT_FOLLOWLOCATION"); + } + + property = property_bag.find(StreamsFactory::StreamProperties::kCurlHttp_MaxRedirs); + if (property != property_bag.end()) + { + return_code = curl_easy_setopt(up_curl_handle.get(), CURLOPT_MAXREDIRS, property->second.GetAsInt32OrThrow()); + ThrowIfCurlSetOptError(return_code, "CURLOPT_MAXREDIRS"); + } + this->curl_handle_ = up_curl_handle.release(); this->curl_url_handle_ = up_curl_url_handle.release(); } diff --git a/Src/libCZI/libCZI_StreamsLib.h b/Src/libCZI/libCZI_StreamsLib.h index ce573f4b..0e03bc22 100644 --- a/Src/libCZI/libCZI_StreamsLib.h +++ b/Src/libCZI/libCZI_StreamsLib.h @@ -224,6 +224,10 @@ namespace libCZI kCurlHttp_SslVerifyPeer = 106, ///< For CurlHttpInputStream, type bool: a boolean indicating whether the SSL-certificate of the remote host is to be verified, c.f. https://curl.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html for more information. kCurlHttp_SslVerifyHost = 107, ///< For CurlHttpInputStream, type bool: a boolean indicating whether the SSL-certificate's name is to be verified against host, c.f. https://curl.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html for more information. + + kCurlHttp_FollowLocation = 108, ///< For CurlHttpInputStream, type bool: a boolean indicating whether redirects are to be followed, c.f. https://curl.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html for more information. + + kCurlHttp_MaxRedirs = 109, ///< For CurlHttpInputStream, type int32: gives the maximum number of redirects to follow, c.f. https://curl.se/libcurl/c/CURLOPT_MAXREDIRS.html for more information. }; };