From a1ea72d719b63a4d2b6421ce2e53b7e3ab12a8a1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 23 Feb 2024 18:50:28 +0300 Subject: Add curl constructors which allow to adjust curl command line --- libbutl/curl.hxx | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'libbutl/curl.hxx') diff --git a/libbutl/curl.hxx b/libbutl/curl.hxx index 3fa7890..ea91807 100644 --- a/libbutl/curl.hxx +++ b/libbutl/curl.hxx @@ -91,6 +91,19 @@ namespace butl public: enum method_type {get, put, post}; + // By default the -sS and, for the HTTP protocol, --fail and --location + // options are passed to curl on the command line. Optionally, these + // options can be suppressed. + // + enum class flags: std::uint16_t + { + no_fail = 0x01, // Don't pass --fail. + no_location = 0x02, // Don't pass --location + no_sS = 0x04, // Don't pass -sS + + none = 0 // Default options set. + }; + ifdstream in; ofdstream out; @@ -121,6 +134,35 @@ namespace butl const std::string& url, A&&... options); + // Similar to the above, but allows to adjust the curl's default command + // line. + // + template + curl (I&& in, + O&& out, + E&& err, + method_type, + flags, + const std::string& url, + A&&... options); + + template + curl (const C&, + I&& in, + O&& out, + E&& err, + method_type, + flags, + const std::string& url, + A&&... options); + // Read the HTTP response status from an input stream. // // Specifically, read and parse the HTTP status line, by default skip over @@ -159,7 +201,10 @@ namespace butl using method_proto_options = small_vector; method_proto - translate (method_type, const std::string& url, method_proto_options&); + translate (method_type, + const std::string& url, + method_proto_options&, + flags); private: template @@ -199,6 +244,11 @@ namespace butl typename std::enable_if::value, O>::type map_out (O&&, method_proto, io_data&); }; + + curl::flags operator& (curl::flags, curl::flags); + curl::flags operator| (curl::flags, curl::flags); + curl::flags operator&= (curl::flags&, curl::flags); + curl::flags operator|= (curl::flags&, curl::flags); } #include -- cgit v1.1