]> granicus.if.org Git - apache/commitdiff
add a ProxyTimeout directive
authorIan Holsman <ianh@apache.org>
Wed, 30 Jan 2002 18:46:56 +0000 (18:46 +0000)
committerIan Holsman <ianh@apache.org>
Wed, 30 Jan 2002 18:46:56 +0000 (18:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93117 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/mod_proxy.html
modules/proxy/mod_proxy.c
modules/proxy/mod_proxy.h
modules/proxy/proxy_connect.c
modules/proxy/proxy_ftp.c
modules/proxy/proxy_http.c

diff --git a/CHANGES b/CHANGES
index 24f15a19da08110ae4ba38ecee21191790906919..b0518b1f15b08e1883d1403cf6431b86daa980b1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,6 @@
 Changes with Apache 2.0.31-dev
+  *) Add a timeout option to the proxy code 'ProxyTimeout' 
+     [Ian Holsman]
 
   *) FTP directory listings are now always retrieved in ASCII mode.
      The FTP proxy properly escapes URI's and HTML in the generated
index db7f2bf49d23720021b18b030794d989a63061e2..c98ebc04e31fafd86190f7949cb2f9e308053f8e 100644 (file)
@@ -84,6 +84,7 @@ into a new module, mod_cache.
 <li><a href="#proxyreceivebuffersize">ProxyReceiveBufferSize</a>
 <li><a href="#proxyremote">ProxyRemote</a>
 <li><a href="#proxyrequests">ProxyRequests</a>
+<li><a href="#proxytimeout">ProxyTimeout</a>
 <li><a href="#proxyvia">ProxyVia</a>
 
 </ul>
@@ -878,6 +879,45 @@ The arguments to the NoProxy directive are one of the following type list:
 
 <hr>
 
+<h2><a name="proxytimeout">ProxyTimeout</a> directive</h2>
+<a
+ href="directive-dict.html#Syntax"
+ REL="Help"
+><strong>Syntax:</strong></a> ProxyTimeout <em>n</em> seconds<br>
+<a
+ href="directive-dict.html#Default"
+ REL="Help"
+><strong>Default:</strong></a> <em>server default timeout</em><br>
+<a
+ href="directive-dict.html#Context"
+ REL="Help"
+><strong>Context:</strong></a> server config, virtual host<br>
+<a
+ href="directive-dict.html#Override"
+ REL="Help"
+><strong>Override:</strong></a> <em>Not applicable</em><br>
+<a
+ href="directive-dict.html#Status"
+ REL="Help"
+><strong>Status:</strong></a> Base<br>
+<a
+ href="directive-dict.html#Module"
+ REL="Help"
+><strong>Module:</strong></a> mod_proxy<br>
+<a
+ href="directive-dict.html#Compatibility"
+ REL="Help"
+><strong>Compatibility:</strong></a> ProxyDomain is only available in
+Apache 2.0.31 and later.<p>
+
+<p>This directive allows a user to specifiy a timeout on proxy requests.
+This is usefull when you have a slow/buggy appserver which hangs,
+and you would rather just return a timeout and fail gracefully instead
+of waiting however long it takes the server to return
+</p>
+<hr>
+
+
 <h2><a name="proxydomain">ProxyDomain</a> directive</h2>
 <a
  href="directive-dict.html#Syntax"
index f797b04eaaa94a2ab5f7b9f6febd4a216f6d59cf..bf3dbb3919a450b99455861b7caa6dbf55b53d75 100644 (file)
@@ -494,6 +494,8 @@ static void * create_proxy_config(apr_pool_t *p, server_rec *s)
     ps->error_override_set = 0; 
     ps->preserve_host_set =0;
     ps->preserve_host =0;    
+    ps->timeout=0;
+    ps->timeout_set=0;
     return ps;
 }
 
@@ -518,6 +520,7 @@ static void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
     ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd;
     ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override;
     ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host;
+    ps->timeout= (overrides->timeout_set == 0) ? base->timeout : overrides->timeout;
 
     return ps;
 }
@@ -823,6 +826,22 @@ static const char *
     psf->maxfwd_set = 1;
     return NULL;
 }
+static const char*
+    set_proxy_timeout(cmd_parms *parms, void *dummy, const char *arg)
+{
+    proxy_server_conf *psf =
+    ap_get_module_config(parms->server->module_config, &proxy_module);
+    int timeout;
+
+    timeout=atoi(arg);
+    if (timeout<1) {
+        return "Proxy Timeout must be at least 1 second.";
+    }
+    psf->timeout_set=1;
+    psf->timeout=timeout;
+
+    return NULL;    
+}
 
 static const char*
     set_via_opt(cmd_parms *parms, void *dummy, const char *arg)
@@ -968,6 +987,9 @@ static const command_rec proxy_cmds[] =
      "use our error handling pages instead of the servers' we are proxying"),
     AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF,
      "on if we should preserve host header while proxying"),
+    AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF,
+     "Set the timeout (in seconds) for a proxied connection. "
+     "This overrides the server timeout"),
  
     {NULL}
 };
index fa6a8cff5e53157d94a5da434695e02533d2a89e..df7a0b67d1747435ceff59c2bfdfb30eb6ce1f36 100644 (file)
@@ -189,6 +189,8 @@ typedef struct {
     int error_override_set;
     int preserve_host;
     int preserve_host_set;
+    int timeout;
+    int timeout_set;
 
 } proxy_server_conf;
 
index 1b13efab0086218a3b35ef8422c347dc9454b93a..c898a61dc93cbe19c5029a31b2b6830cab38c9f3 100644 (file)
@@ -247,7 +247,16 @@ int ap_proxy_connect_handler(request_rec *r, proxy_server_conf *conf,
             }
 
             /* Set a timeout on the socket */
-            apr_setsocketopt(sock, APR_SO_TIMEOUT, (int)(r->server->timeout * APR_USEC_PER_SEC));
+            if (conf->timeout_set == 1 ) {
+                apr_setsocketopt(sock, 
+                                 APR_SO_TIMEOUT, 
+                                 (int)(conf->timeout * APR_USEC_PER_SEC));
+            }
+            else {
+                apr_setsocketopt(sock, 
+                                 APR_SO_TIMEOUT, 
+                                 (int)(r->server->timeout * APR_USEC_PER_SEC));
+            }
 
            /* make the connection out of the socket */
            rv = apr_connect(sock, connect_addr);
index 3447f54220a2c2ddaa76a66c5dcf68250aed2183..2f5d10c49572eccda823d68b89341e141e5f403f 100644 (file)
@@ -897,7 +897,16 @@ int ap_proxy_ftp_handler(request_rec *r, proxy_server_conf *conf,
     }
 
     /* Set a timeout on the socket */
-    apr_setsocketopt(sock, APR_SO_TIMEOUT, (int)(r->server->timeout * APR_USEC_PER_SEC));
+    if (conf->timeout_set == 1) {
+        apr_setsocketopt(sock, 
+                         APR_SO_TIMEOUT, 
+                         (int)(conf->timeout * APR_USEC_PER_SEC));
+    }
+    else {
+        apr_setsocketopt(sock, 
+                         APR_SO_TIMEOUT, 
+                         (int)(r->server->timeout * APR_USEC_PER_SEC));
+    }
 
     ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r->server,
                  "proxy: FTP: socket has been created");
index 35b2bc78b0cb795c08e60c1a3375720d26d18891..ff69dd29880c508e2857071541381faf79c7cf41 100644 (file)
@@ -385,8 +385,14 @@ apr_status_t ap_proxy_http_create_connection(apr_pool_t *p, request_rec *r,
 #endif
 
             /* Set a timeout on the socket */
-            apr_setsocketopt(p_conn->sock, APR_SO_TIMEOUT,
+            if (conf->timeout_set == 1) {
+                apr_setsocketopt(p_conn->sock, APR_SO_TIMEOUT,
+                             (int)(conf->timeout * APR_USEC_PER_SEC));
+            } 
+            else {
+                apr_setsocketopt(p_conn->sock, APR_SO_TIMEOUT,
                              (int)(r->server->timeout * APR_USEC_PER_SEC));
+            }
 
             ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r->server,
                          "proxy: socket has been created");