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

85cb4d
diff --git a/docs/manual/mod/mod_proxy_wstunnel.html.en b/docs/manual/mod/mod_proxy_wstunnel.html.en
85cb4d
index 21ffbe2..16e1628 100644
85cb4d
--- a/docs/manual/mod/mod_proxy_wstunnel.html.en
85cb4d
+++ b/docs/manual/mod/mod_proxy_wstunnel.html.en
85cb4d
@@ -60,14 +60,33 @@ NONE means you bypass the check for the header but still upgrade to WebSocket.
85cb4d
 ANY means that Upgrade will read in the request headers and use
85cb4d
 in the response Upgrade

85cb4d
 
85cb4d
-
Support Apache!

Directives

85cb4d
-

This module provides no

85cb4d
-            directives.

85cb4d
+

Directives

85cb4d
+
    85cb4d
    +
  • ProxyWebsocketIdleTimeout
  • 85cb4d
    +
    85cb4d
    +
    85cb4d
     

    Bugfix checklist

    See also

    85cb4d
     
      85cb4d
       
    • mod_proxy
    • 85cb4d
       
    • Comments
    • 85cb4d
       
      85cb4d
      +
      top
      6953a2
      +
      85cb4d
      +
      85cb4d
      +Description:Sets the maximum amount of time to wait for data on the websockets tunnel
      85cb4d
      +Syntax:ProxyWebsocketIdleTimeout num[ms]
      85cb4d
      +Default:ProxyWebsocketIdleTimeout 0
      85cb4d
      +Context:server config, virtual host
      85cb4d
      +Status:Extension
      85cb4d
      +Module:mod_proxy_wstunnel
      85cb4d
      +
      85cb4d
      +    

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

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

      85cb4d
      +
      85cb4d
      +
      85cb4d
      +
      85cb4d
       
      85cb4d
       
      85cb4d
       

      Available Languages:  en  |

      85cb4d
      diff --git a/modules/proxy/mod_proxy_wstunnel.c b/modules/proxy/mod_proxy_wstunnel.c
      85cb4d
      index 4aadbab..ca3ed3a 100644
      85cb4d
      --- a/modules/proxy/mod_proxy_wstunnel.c
      85cb4d
      +++ b/modules/proxy/mod_proxy_wstunnel.c
      85cb4d
      @@ -18,6 +18,10 @@
      85cb4d
       
      85cb4d
       module AP_MODULE_DECLARE_DATA proxy_wstunnel_module;
      85cb4d
       
      85cb4d
      +typedef struct {
      85cb4d
      +    apr_time_t idle_timeout;
      85cb4d
      +} proxyws_dir_conf;
      85cb4d
      +
      85cb4d
       /*
      85cb4d
        * Canonicalise http-like URLs.
      85cb4d
        * scheme is the scheme for the URL
      85cb4d
      @@ -108,6 +112,8 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
      85cb4d
           conn_rec *c = r->connection;
      85cb4d
           apr_socket_t *sock = conn->sock;
      85cb4d
           conn_rec *backconn = conn->connection;
      85cb4d
      +    proxyws_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
      85cb4d
      +                                                   &proxy_wstunnel_module);
      85cb4d
           char *buf;
      85cb4d
           apr_bucket_brigade *header_brigade;
      85cb4d
           apr_bucket *e;
      85cb4d
      @@ -185,10 +191,13 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
      85cb4d
           c->keepalive = AP_CONN_CLOSE;
      85cb4d
       
      85cb4d
           do { /* Loop until done (one side closes the connection, or an error) */
      85cb4d
      -        rv = apr_pollset_poll(pollset, -1, &pollcnt, &signalled);
      85cb4d
      +        rv = apr_pollset_poll(pollset, dconf->idle_timeout, &pollcnt, &signalled);
      85cb4d
               if (rv != APR_SUCCESS) {
      85cb4d
                   if (APR_STATUS_IS_EINTR(rv)) {
      85cb4d
                       continue;
      85cb4d
      +            } else if(APR_STATUS_IS_TIMEUP(rv)){
      85cb4d
      +               ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "RH: the connection has timed out");
      85cb4d
      +               return HTTP_REQUEST_TIME_OUT;
      85cb4d
                   }
      85cb4d
                   ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02444) "error apr_poll()");
      85cb4d
                   return HTTP_INTERNAL_SERVER_ERROR;
      85cb4d
      @@ -366,6 +375,38 @@ cleanup:
      85cb4d
           return status;
      85cb4d
       }
      85cb4d
       
      85cb4d
      +static const char * proxyws_set_idle(cmd_parms *cmd, void *conf, const char *val)
      85cb4d
      +{
      85cb4d
      +    proxyws_dir_conf *dconf = conf;
      85cb4d
      +    if (ap_timeout_parameter_parse(val, &(dconf->idle_timeout), "s") != APR_SUCCESS)
      85cb4d
      +        return "ProxyWebsocketIdleTimeout timeout has wrong format";
      85cb4d
      +
      85cb4d
      +    if (dconf->idle_timeout < 0)
      85cb4d
      +        return "ProxyWebsocketIdleTimeout timeout has to be a non-negative number";
      85cb4d
      +
      85cb4d
      +    if (!dconf->idle_timeout) dconf->idle_timeout = -1; /* loop indefinitely */
      85cb4d
      +
      85cb4d
      +    return NULL;
      85cb4d
      +}
      85cb4d
      +
      85cb4d
      +static void *create_proxyws_dir_config(apr_pool_t *p, char *dummy)
      85cb4d
      +{
      85cb4d
      +    proxyws_dir_conf *new =
      85cb4d
      +        (proxyws_dir_conf *) apr_pcalloc(p, sizeof(proxyws_dir_conf));
      85cb4d
      +
      85cb4d
      +    new->idle_timeout = -1; /* no timeout */
      85cb4d
      +
      85cb4d
      +    return (void *) new;
      85cb4d
      +}
      85cb4d
      +
      85cb4d
      +static const command_rec ws_proxy_cmds[] =
      85cb4d
      +{
      85cb4d
      +    AP_INIT_TAKE1("ProxyWebsocketIdleTimeout", proxyws_set_idle, NULL, RSRC_CONF|ACCESS_CONF,
      85cb4d
      +                 "timeout for activity in either direction, unlimited by default."),
      85cb4d
      +
      85cb4d
      +    {NULL}
      85cb4d
      +};
      85cb4d
      +
      85cb4d
       static void ap_proxy_http_register_hook(apr_pool_t *p)
      85cb4d
       {
      85cb4d
           proxy_hook_scheme_handler(proxy_wstunnel_handler, NULL, NULL, APR_HOOK_FIRST);
      85cb4d
      @@ -374,10 +415,10 @@ static void ap_proxy_http_register_hook(apr_pool_t *p)
      85cb4d
       
      85cb4d
       AP_DECLARE_MODULE(proxy_wstunnel) = {
      85cb4d
           STANDARD20_MODULE_STUFF,
      85cb4d
      -    NULL,                       /* create per-directory config structure */
      85cb4d
      +    create_proxyws_dir_config,  /* create per-directory config structure */
      85cb4d
           NULL,                       /* merge per-directory config structures */
      85cb4d
           NULL,                       /* create per-server config structure */
      85cb4d
           NULL,                       /* merge per-server config structures */
      85cb4d
      -    NULL,                       /* command apr_table_t */
      85cb4d
      +    ws_proxy_cmds,              /* command apr_table_t */
      85cb4d
           ap_proxy_http_register_hook /* register hooks */
      85cb4d
       };