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

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

ca8514
 
ca8514
-
Support Apache!

Directives

ca8514
-

This module provides no

ca8514
-            directives.

ca8514
+

Directives

ca8514
+
    ca8514
    +
  • ProxyWebsocketIdleTimeout
  • ca8514
    +
    ca8514
    +
    ca8514
     

    Bugfix checklist

    See also

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

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

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

      ca8514
      +
      ca8514
      +
      ca8514
      +
      ca8514
       
      ca8514
       
      ca8514
       

      Available Languages:  en  |

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