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

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

0e3136
 
Support Apache!

Directives

0e3136
 
    0e3136
     
  • ProxyWebsocketFallbackToProxyHttp
  • 0e3136
    +
  • ProxyWebsocketIdleTimeout
  • 0e3136
     
    0e3136
     

    Bugfix checklist

    See also

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

      0e3136
           WebSocket requests as in httpd 2.4.46 and earlier.

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

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

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

      0e3136
      +
      0e3136
      +
      0e3136
      +
      0e3136
       
      0e3136
       
      0e3136
       

      Available Languages:  en  |

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