From a5ce2da8a276cfb55ec72e8f9230fe30cff76a05 Mon Sep 17 00:00:00 2001 From: Ian Holsman Date: Wed, 30 Jan 2002 18:46:56 +0000 Subject: [PATCH] add a ProxyTimeout directive git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93117 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 2 ++ docs/manual/mod/mod_proxy.html | 40 ++++++++++++++++++++++++++++++++++ modules/proxy/mod_proxy.c | 22 +++++++++++++++++++ modules/proxy/mod_proxy.h | 2 ++ modules/proxy/proxy_connect.c | 11 +++++++++- modules/proxy/proxy_ftp.c | 11 +++++++++- modules/proxy/proxy_http.c | 8 ++++++- 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.
  • ProxyReceiveBufferSize
  • ProxyRemote
  • ProxyRequests +
  • ProxyTimeout
  • ProxyVia @@ -878,6 +879,45 @@ The arguments to the NoProxy directive are one of the following type list:
    +

    ProxyTimeout directive

    +Syntax: ProxyTimeout n seconds
    +Default: server default timeout
    +Context: server config, virtual host
    +Override: Not applicable
    +Status: Base
    +Module: mod_proxy
    +Compatibility: ProxyDomain is only available in +Apache 2.0.31 and later.

    + +

    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 +

    +
    + +

    ProxyDomain directive

    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"); -- 2.40.0