summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Holsman <ianh@apache.org>2002-01-30 18:46:56 +0000
committerIan Holsman <ianh@apache.org>2002-01-30 18:46:56 +0000
commit8cf569593b17fd63e35e745398e2a8a9e5c3e25e (patch)
tree110763508f1758db5e8c8b3439d5ab7282077124
parent9649031808755d5f937b32721da11d98fa72ea39 (diff)
downloadhttpd-8cf569593b17fd63e35e745398e2a8a9e5c3e25e.tar.gz
add a ProxyTimeout directive
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93117 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES2
-rw-r--r--docs/manual/mod/mod_proxy.html40
-rw-r--r--modules/proxy/mod_proxy.c22
-rw-r--r--modules/proxy/mod_proxy.h2
-rw-r--r--modules/proxy/proxy_connect.c11
-rw-r--r--modules/proxy/proxy_ftp.c11
-rw-r--r--modules/proxy/proxy_http.c8
7 files changed, 93 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 24f15a19da..b0518b1f15 100644
--- 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
diff --git a/docs/manual/mod/mod_proxy.html b/docs/manual/mod/mod_proxy.html
index db7f2bf49d..c98ebc04e3 100644
--- a/docs/manual/mod/mod_proxy.html
+++ b/docs/manual/mod/mod_proxy.html
@@ -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"
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
index f797b04eaa..bf3dbb3919 100644
--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -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}
};
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
index fa6a8cff5e..df7a0b67d1 100644
--- a/modules/proxy/mod_proxy.h
+++ b/modules/proxy/mod_proxy.h
@@ -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;
diff --git a/modules/proxy/proxy_connect.c b/modules/proxy/proxy_connect.c
index 1b13efab00..c898a61dc9 100644
--- a/modules/proxy/proxy_connect.c
+++ b/modules/proxy/proxy_connect.c
@@ -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);
diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c
index 3447f54220..2f5d10c495 100644
--- a/modules/proxy/proxy_ftp.c
+++ b/modules/proxy/proxy_ftp.c
@@ -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");
diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c
index 35b2bc78b0..ff69dd2988 100644
--- a/modules/proxy/proxy_http.c
+++ b/modules/proxy/proxy_http.c
@@ -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");