]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8560 [mod_http_cache] add new parameter, connect-timeout
authorChris Rienzo <chris.rienzo@citrix.com>
Thu, 19 Nov 2015 22:10:15 +0000 (17:10 -0500)
committerChris Rienzo <chris.rienzo@citrix.com>
Thu, 19 Nov 2015 22:10:15 +0000 (17:10 -0500)
This is the maximum time to wait, in seconds, for the HTTP GET or PUT to connect.
If this value is not set or is set to 0, the default setting of 300 seconds is used.

src/mod/applications/mod_http_cache/conf/autoload_configs/http_cache.conf.xml
src/mod/applications/mod_http_cache/mod_http_cache.c

index a5c3f46c76e794ebcd75c529e1bff68c9a25e23a..3cb24348c63fd01fd68bc269174e948773540eb1 100644 (file)
@@ -8,6 +8,8 @@
     <param name="ssl-cacert" value="$${base_dir}/conf/cacert.pem"/>
     <param name="ssl-verifyhost" value="true"/>
     <param name="ssl-verifypeer" value="true"/>
+    <!-- default is 300 seconds, override here -->
+    <!--param name="connect-timeout" value="300"/>
   </settings>
 
   <profiles>
index 5eb9b1059c039062212daa6c3e31542ac22b1ef3..60ed37dd2513b74f10e218d65609241aa1181fb0 100644 (file)
@@ -199,6 +199,8 @@ struct url_cache {
        int ssl_verifyhost;
        /** True if http/https file formats should be loaded */
        int enable_file_formats;
+       /** How long to wait, in seconds, for TCP connection.  If 0, use default value of 300 seconds */
+       long connect_timeout;
 };
 static url_cache_t gcache;
 
@@ -326,6 +328,9 @@ static switch_status_t http_put(url_cache_t *cache, http_profile_t *profile, swi
        switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
        switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
        switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
+       if (cache->connect_timeout > 0) {
+               switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, cache->connect_timeout);
+       }
        if (!cache->ssl_verifypeer) {
                switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
        } else {
@@ -1075,6 +1080,9 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
                switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
                switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *) url);
                switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
+               if (cache->connect_timeout > 0) {
+                       switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, cache->connect_timeout);
+               }
                if (!cache->ssl_verifypeer) {
                        switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
                } else {
@@ -1477,6 +1485,7 @@ static switch_status_t do_config(url_cache_t *cache)
        cache->ssl_verifyhost = 1;
        cache->ssl_verifypeer = 1;
        cache->enable_file_formats = 0;
+       cache->connect_timeout = 0;
 
        /* get params */
        settings = switch_xml_child(cfg, "settings");
@@ -1513,6 +1522,9 @@ static switch_status_t do_config(url_cache_t *cache)
                        } else if (!strcasecmp(var, "ssl-verifypeer")) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting ssl-verifypeer to %s\n", val);
                                cache->ssl_verifypeer = !switch_false(val); /* only disable if explicitly set to false */
+                       } else if (!strcasecmp(var, "connect-timeout")) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting connect-timeout to %s\n", val);
+                               cache->connect_timeout = atoi(val);
                        } else {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unsupported param: %s\n", var);
                        }
@@ -1623,6 +1635,11 @@ static switch_status_t do_config(url_cache_t *cache)
                status = SWITCH_STATUS_TERM;
                goto done;
        }
+       if (cache->connect_timeout < 0) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "connect-timeout must be >= 0\n");
+               status = SWITCH_STATUS_TERM;
+               goto done;
+       }
 
        cache->max_url = max_urls;
        cache->default_max_age = (default_max_age_sec * 1000 * 1000); /* convert from seconds to nanoseconds */