Blame SOURCES/httpd-2.4.48-proxy-ws-idle-timeout.patch

906948
diff --git a/docs/manual/mod/mod_proxy_wstunnel.html.en b/docs/manual/mod/mod_proxy_wstunnel.html.en
906948
index 9f2c120..61ff7de 100644
906948
--- a/docs/manual/mod/mod_proxy_wstunnel.html.en
906948
+++ b/docs/manual/mod/mod_proxy_wstunnel.html.en
906948
@@ -83,6 +83,7 @@ in the response Upgrade

906948
 
Support Apache!

Directives

906948
 
    906948
     
  • ProxyWebsocketFallbackToProxyHttp
  • 906948
    +
  • ProxyWebsocketIdleTimeout
  • 906948
     
    906948
     

    Bugfix checklist

    See also

    906948
     
      906948
      @@ -108,6 +109,23 @@ in the response Upgrade

      906948
           WebSocket requests as in httpd 2.4.46 and earlier.

      906948
       
      906948
       
      906948
      +
      906948
      +
      906948
      +
      906948
      +Description:Sets the maximum amount of time to wait for data on the websockets tunnel
      906948
      +Syntax:ProxyWebsocketIdleTimeout num[ms]
      906948
      +Default:ProxyWebsocketIdleTimeout 0
      906948
      +Context:server config, virtual host
      906948
      +Status:Extension
      906948
      +Module:mod_proxy_wstunnel
      906948
      +
      906948
      +    

      This directive imposes a maximum amount of time for the tunnel to be

      906948
      +    left open while idle. The timeout is considered in seconds by default, but
      906948
      +    it is possible to increase the time resolution to milliseconds
      906948
      +    adding the ms suffix.

      906948
      +
      906948
      +
      906948
      +
      906948
       
      906948
       
      906948
       

      Available Languages:  en  |

      906948
      diff --git a/modules/proxy/mod_proxy_wstunnel.c b/modules/proxy/mod_proxy_wstunnel.c
      906948
      index bcbba42..c29ded1 100644
      906948
      --- a/modules/proxy/mod_proxy_wstunnel.c
      906948
      +++ b/modules/proxy/mod_proxy_wstunnel.c
      906948
      @@ -22,6 +22,7 @@ module AP_MODULE_DECLARE_DATA proxy_wstunnel_module;
      906948
       typedef struct {
      906948
           unsigned int fallback_to_proxy_http     :1,
      906948
                        fallback_to_proxy_http_set :1;
      906948
      +    apr_time_t idle_timeout;
      906948
       } proxyws_dir_conf;
      906948
       
      906948
       static int can_fallback_to_proxy_http;
      906948
      @@ -152,6 +153,8 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
      906948
           conn_rec *c = r->connection;
      906948
           apr_socket_t *sock = conn->sock;
      906948
           conn_rec *backconn = conn->connection;
      906948
      +    proxyws_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
      906948
      +                                                   &proxy_wstunnel_module);
      906948
           char *buf;
      906948
           apr_bucket_brigade *header_brigade;
      906948
           apr_bucket *e;
      906948
      @@ -229,10 +232,13 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
      906948
           c->keepalive = AP_CONN_CLOSE;
      906948
       
      906948
           do { /* Loop until done (one side closes the connection, or an error) */
      906948
      -        rv = apr_pollset_poll(pollset, -1, &pollcnt, &signalled);
      906948
      +        rv = apr_pollset_poll(pollset, dconf->idle_timeout, &pollcnt, &signalled);
      906948
               if (rv != APR_SUCCESS) {
      906948
                   if (APR_STATUS_IS_EINTR(rv)) {
      906948
                       continue;
      906948
      +            } else if(APR_STATUS_IS_TIMEUP(rv)){
      906948
      +               ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "RH: the connection has timed out");
      906948
      +               return HTTP_REQUEST_TIME_OUT;
      906948
                   }
      906948
                   ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02444) "error apr_poll()");
      906948
                   return HTTP_INTERNAL_SERVER_ERROR;
      906948
      @@ -418,11 +424,26 @@ cleanup:
      906948
           return status;
      906948
       }
      906948
       
      906948
      +static const char * proxyws_set_idle(cmd_parms *cmd, void *conf, const char *val)
      906948
      +{
      906948
      +    proxyws_dir_conf *dconf = conf;
      906948
      +    if (ap_timeout_parameter_parse(val, &(dconf->idle_timeout), "s") != APR_SUCCESS)
      906948
      +        return "ProxyWebsocketIdleTimeout timeout has wrong format";
      906948
      +
      906948
      +    if (dconf->idle_timeout < 0)
      906948
      +        return "ProxyWebsocketIdleTimeout timeout has to be a non-negative number";
      906948
      +
      906948
      +    if (!dconf->idle_timeout) dconf->idle_timeout = -1; /* loop indefinitely */
      906948
      +
      906948
      +    return NULL;
      906948
      +}
      906948
      +
      906948
       static void *create_proxyws_dir_config(apr_pool_t *p, char *dummy)
      906948
       {
      906948
           proxyws_dir_conf *new =
      906948
               (proxyws_dir_conf *) apr_pcalloc(p, sizeof(proxyws_dir_conf));
      906948
       
      906948
      +    new->idle_timeout = -1; /* no timeout */
      906948
           new->fallback_to_proxy_http = 1;
      906948
       
      906948
           return (void *) new;
      906948
      @@ -465,7 +486,8 @@ static const command_rec ws_proxy_cmds[] =
      906948
                        proxyws_fallback_to_proxy_http, NULL, RSRC_CONF|ACCESS_CONF,
      906948
                        "whether to let mod_proxy_http handle the upgrade and tunneling, "
      906948
                        "On by default"),
      906948
      -
      906948
      +    AP_INIT_TAKE1("ProxyWebsocketIdleTimeout", proxyws_set_idle, NULL, RSRC_CONF|ACCESS_CONF,
      906948
      +                 "timeout for activity in either direction, unlimited by default."),
      906948
           {NULL}
      906948
       };
      906948