From 160f793e2a57010612797ab68d59264aed57d887 Mon Sep 17 00:00:00 2001 From: gd Date: Fri, 14 Oct 2022 11:30:44 +0300 Subject: [PATCH] Added connect_timeout configuration to curl input plugin --- doc/plugins.rst | 12 +++++++++++- src/input/plugins/CurlInputPlugin.cxx | 11 ++++++++++- src/lib/curl/Request.hxx | 4 ++++ src/lib/curl/Setup.cxx | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/doc/plugins.rst b/doc/plugins.rst index 158a8be5a..32d9b2bba 100644 --- a/doc/plugins.rst +++ b/doc/plugins.rst @@ -223,21 +223,31 @@ variables such as ``http_proxy`` or specified in :file:`~/.curlrc` will be in effect. .. list-table:: - :widths: 20 80 + :widths: 20 70 10 :header-rows: 1 * - Setting - Description + - Default * - **proxy** - Sets the address of the HTTP proxy server. + - * - **proxy_user, proxy_password** - Configures proxy authentication. + - * - **verify_peer yes|no** - Verify the peer's SSL certificate? `More information `_. + - yes * - **verify_host yes|no** - Verify the certificate's name against host? `More information `_. + - yes * - **cacert** - Set path to Certificate Authority (CA) bundle `More information `_. + - + * - **connect_timeout** + - Set the the connect phase timeout in seconds. "0" is `libcurl`'s default built-in connection timeout - 300 seconds. + `More information `_. + - 10 ffmpeg ------ diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 1c314c364..40bd9a89b 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -151,6 +151,9 @@ static const char *cacert; static bool verify_peer, verify_host; +/** Connection settings */ +static long connect_timeout; + static CurlInit *curl_init; static constexpr Domain curl_domain("curl"); @@ -374,6 +377,11 @@ input_curl_init(EventLoop &event_loop, const ConfigBlock &block) cacert = block.GetBlockValue("cacert"); verify_peer = block.GetBlockValue("verify_peer", default_verify); verify_host = block.GetBlockValue("verify_host", default_verify); + + constexpr unsigned default_connection_timeout = 10; + unsigned timeout = block.GetBlockValue("connect_timeout", + default_connection_timeout); + connect_timeout = static_cast(timeout); } static void @@ -399,7 +407,7 @@ CurlInputStream::CurlInputStream(EventLoop &event_loop, const char *_url, request_headers.Append("Icy-Metadata: 1"); for (const auto &[key, header] : headers) - request_headers.Append((key + ":" + header).c_str()); + request_headers.Append((key + ":" += header).c_str()); } CurlInputStream::~CurlInputStream() noexcept @@ -439,6 +447,7 @@ CurlInputStream::InitEasy() request->SetOption(CURLOPT_HTTPHEADER, request_headers.Get()); request->SetProxyVerifyPeer(verify_peer); request->SetProxyVerifyHost(verify_host); + request->SetConnectTimeout(connect_timeout); } void diff --git a/src/lib/curl/Request.hxx b/src/lib/curl/Request.hxx index 49552a26f..977c8117d 100644 --- a/src/lib/curl/Request.hxx +++ b/src/lib/curl/Request.hxx @@ -130,6 +130,10 @@ public: easy.SetOption(CURLOPT_PROXY_SSL_VERIFYPEER, value); } + void SetConnectTimeout(long timeout_seconds) { + easy.SetConnectTimeout(timeout_seconds); + } + void SetNoBody(bool value=true) { easy.SetNoBody(value); } diff --git a/src/lib/curl/Setup.cxx b/src/lib/curl/Setup.cxx index 284b7ca79..4baa856d0 100644 --- a/src/lib/curl/Setup.cxx +++ b/src/lib/curl/Setup.cxx @@ -31,7 +31,7 @@ #include "Easy.hxx" #include "Version.h" -#include +#include namespace Curl {