From e03475e1598cc6c32c48ac027ee892114060c0e0 Mon Sep 17 00:00:00 2001
From: Jim Jagielski <jim@apache.org>
Date: Wed, 13 Mar 2019 12:35:53 +0000
Subject: [PATCH] Merge r1853901, r1853906, r1853908, r1853929, r1853935,
 r1853967 from trunk:

mod_reqtimeout: factorize structs and code.

With a bit of macro magic, this is to avoid more code duplication when adding
new stages (next commit will add TLS/handshake timeouts handling in addition to
existing header and body ones).

No functional change here.


mod_reqtimeout: Allow to configure (TLS-)handshake timeouts.

The timeouts apply between the process_connection and pre_read_request hooks.
They are disabled by default for compatibily reasons.


mod_reqtimeout: follow up to r1853906: adjust hooks priorities comments.


mod_reqtimeout: follow up to r1853901: fix macro args.


mod_reqtimeout: follow up to r1853901: init stage name outside INIT_STAGE().

It helps both code readability where stages are initilized and potential
logging in the input filter (even if the stage is disabled).


mod_http2: fix for latest mod_reqtimeout change re handshake timeouts

Submitted by: ylavic, icing
Reviewed by: ylavic, icing, jim

[Ubuntu note: converted upstream mod_reqtimeout.xml changes into
 mod_reqtimeout.html.en changes -- sbeattie]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1855409 13f79535-47bb-0310-9956-ffa450edef68
---
 docs/manual/mod/mod_reqtimeout.html.en |   61 ++++----
 modules/filters/mod_reqtimeout.c       |  227 +++++++++++++++++----------------
 modules/http2/h2_task.c                |    7 -
 3 files changed, 154 insertions(+), 141 deletions(-)

# diff --git a/CHANGES b/CHANGES
# index 791f419a83..c483df1054 100644
# --- a/CHANGES
# +++ b/CHANGES
# @@ -17,6 +17,9 @@ Changes with Apache 2.4.39
#    *) mod_http2: enable re-use of slave connections again. Fixed slave connection
#       keepalives counter. [Stefan Eissing]
#  
# +  *) mod_reqtimeout: Allow to configure (TLS-)handshake timeouts.
# +     PR 61310. [Yann Ylavic]
# +
#    *) mod_proxy_wstunnel: Fix websocket proxy over UDS.
#       PR 62932 <pavel dcmsys.com>
#  
# diff --git a/STATUS b/STATUS
# index 33bb6ff21f..6301b4e2a3 100644
# --- a/STATUS
# +++ b/STATUS
# @@ -126,16 +126,6 @@ RELEASE SHOWSTOPPERS:
#  PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
#    [ start all new proposals below, under PATCHES PROPOSED. ]
#  
# -  *) mod_reqtimeout: Allow to configure (TLS-)handshake timeouts.  PR 61310.
# -     trunk patch: http://svn.apache.org/r1853901
# -                  http://svn.apache.org/r1853906
# -                  http://svn.apache.org/r1853908
# -                  http://svn.apache.org/r1853929
# -                  http://svn.apache.org/r1853935
# -                  http://svn.apache.org/r1853967
# -     2.4.x patch: http://people.apache.org/~ylavic/patches/httpd-2.4.x-reqtimeout_handshake-v2.patch
# -     +1: ylavic, icing, jim
# -     icing: please add r1853967 to this to keep h2 working with this change. if added, +1 
#  
#  PATCHES PROPOSED TO BACKPORT FROM TRUNK:
#    [ New proposals should be added at the end of the list ]
Index: b/modules/filters/mod_reqtimeout.c
===================================================================
--- a/modules/filters/mod_reqtimeout.c
+++ b/modules/filters/mod_reqtimeout.c
@@ -29,23 +29,29 @@
 module AP_MODULE_DECLARE_DATA reqtimeout_module;
 
 #define UNSET                            -1
-#define MRT_DEFAULT_HEADER_TIMEOUT       20
-#define MRT_DEFAULT_HEADER_MAX_TIMEOUT   40
-#define MRT_DEFAULT_HEADER_MIN_RATE      500
-#define MRT_DEFAULT_BODY_TIMEOUT         20
-#define MRT_DEFAULT_BODY_MAX_TIMEOUT     0
-#define MRT_DEFAULT_BODY_MIN_RATE        500
+#define MRT_DEFAULT_handshake_TIMEOUT     0 /* disabled */
+#define MRT_DEFAULT_handshake_MAX_TIMEOUT 0
+#define MRT_DEFAULT_handshake_MIN_RATE    APR_INT32_MAX
+#define MRT_DEFAULT_header_TIMEOUT       20
+#define MRT_DEFAULT_header_MAX_TIMEOUT   40
+#define MRT_DEFAULT_header_MIN_RATE      500
+#define MRT_DEFAULT_body_TIMEOUT         20
+#define MRT_DEFAULT_body_MAX_TIMEOUT     0
+#define MRT_DEFAULT_body_MIN_RATE        500
 
 typedef struct
 {
-    int header_timeout;     /* timeout for reading the req hdrs in secs */
-    int header_max_timeout; /* max timeout for req hdrs in secs */
-    int header_min_rate;    /* min rate for reading req hdrs in bytes/s */
-    apr_time_t header_rate_factor;
-    int body_timeout;       /* timeout for reading the req body in secs */
-    int body_max_timeout;   /* max timeout for req body in secs */
-    int body_min_rate;      /* min rate for reading req body in bytes/s */
-    apr_time_t body_rate_factor;
+    int timeout;            /* timeout in secs */
+    int max_timeout;        /* max timeout in secs */
+    int min_rate;           /* min rate in bytes/s */
+    apr_time_t rate_factor; /* scale factor (#usecs per min_rate) */
+} reqtimeout_stage_t;
+
+typedef struct
+{
+    reqtimeout_stage_t handshake;   /* Handshaking (TLS) */
+    reqtimeout_stage_t header;      /* Reading the HTTP header */
+    reqtimeout_stage_t body;        /* Reading the HTTP body */
 } reqtimeout_srv_cfg;
 
 /* this struct is used both as conn_config and as filter context */
@@ -53,17 +59,15 @@ typedef struct
 {
     apr_time_t timeout_at;
     apr_time_t max_timeout_at;
-    int min_rate;
-    int new_timeout;
-    int new_max_timeout;
+    reqtimeout_stage_t cur_stage;
     int in_keep_alive;
     char *type;
     apr_socket_t *socket;
-    apr_time_t rate_factor;
     apr_bucket_brigade *tmpbb;
 } reqtimeout_con_cfg;
 
 static const char *const reqtimeout_filter_name = "reqtimeout";
+static int default_handshake_rate_factor;
 static int default_header_rate_factor;
 static int default_body_rate_factor;
 
@@ -75,7 +79,7 @@ static void extend_timeout(reqtimeout_co
     if (apr_brigade_length(bb, 0, &len) != APR_SUCCESS || len <= 0)
         return;
 
-    new_timeout_at = ccfg->timeout_at + len * ccfg->rate_factor;
+    new_timeout_at = ccfg->timeout_at + len * ccfg->cur_stage.rate_factor;
     if (ccfg->max_timeout_at > 0 && new_timeout_at > ccfg->max_timeout_at) {
         ccfg->timeout_at = ccfg->max_timeout_at;
     }
@@ -190,14 +194,14 @@ static apr_status_t reqtimeout_filter(ap
         apr_brigade_cleanup(bb);
     }
 
-    if (ccfg->new_timeout > 0) {
+    if (ccfg->cur_stage.timeout > 0) {
         /* set new timeout */
         now = apr_time_now();
-        ccfg->timeout_at = now + apr_time_from_sec(ccfg->new_timeout);
-        ccfg->new_timeout = 0;
-        if (ccfg->new_max_timeout > 0) {
-            ccfg->max_timeout_at = now + apr_time_from_sec(ccfg->new_max_timeout);
-            ccfg->new_max_timeout = 0;
+        ccfg->timeout_at = now + apr_time_from_sec(ccfg->cur_stage.timeout);
+        ccfg->cur_stage.timeout = 0;
+        if (ccfg->cur_stage.max_timeout > 0) {
+            ccfg->max_timeout_at = now + apr_time_from_sec(ccfg->cur_stage.max_timeout);
+            ccfg->cur_stage.max_timeout = 0;
         }
     }
     else if (ccfg->timeout_at == 0) {
@@ -216,7 +220,7 @@ static apr_status_t reqtimeout_filter(ap
     if (block == APR_NONBLOCK_READ || mode == AP_MODE_INIT
         || mode == AP_MODE_EATCRLF) {
         rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
-        if (ccfg->min_rate > 0 && rv == APR_SUCCESS) {
+        if (ccfg->cur_stage.rate_factor > 0 && rv == APR_SUCCESS) {
             extend_timeout(ccfg, bb);
         }
         return rv;
@@ -250,7 +254,7 @@ static apr_status_t reqtimeout_filter(ap
             }
 
             if (!APR_BRIGADE_EMPTY(bb)) {
-                if (ccfg->min_rate > 0) {
+                if (ccfg->cur_stage.rate_factor > 0) {
                     extend_timeout(ccfg, bb);
                 }
 
@@ -311,7 +315,7 @@ static apr_status_t reqtimeout_filter(ap
          * the real (relevant) bytes to be asked later, within the
          * currently alloted time.
          */
-        if (ccfg->min_rate > 0 && rv == APR_SUCCESS
+        if (ccfg->cur_stage.rate_factor > 0 && rv == APR_SUCCESS
                 && mode != AP_MODE_SPECULATIVE) {
             extend_timeout(ccfg, bb);
         }
@@ -350,6 +354,19 @@ static apr_status_t reqtimeout_eor(ap_fi
     return ap_pass_brigade(f->next, bb);
 }
 
+#define INIT_STAGE(cfg, ccfg, stage) do { \
+    if (cfg->stage.timeout != UNSET) { \
+        ccfg->cur_stage.timeout     = cfg->stage.timeout; \
+        ccfg->cur_stage.max_timeout = cfg->stage.max_timeout; \
+        ccfg->cur_stage.rate_factor = cfg->stage.rate_factor; \
+    } \
+    else { \
+        ccfg->cur_stage.timeout     = MRT_DEFAULT_##stage##_TIMEOUT; \
+        ccfg->cur_stage.max_timeout = MRT_DEFAULT_##stage##_MAX_TIMEOUT; \
+        ccfg->cur_stage.rate_factor = default_##stage##_rate_factor; \
+    } \
+} while (0)
+
 static int reqtimeout_init(conn_rec *c)
 {
     reqtimeout_con_cfg *ccfg;
@@ -358,7 +375,11 @@ static int reqtimeout_init(conn_rec *c)
     cfg = ap_get_module_config(c->base_server->module_config,
                                &reqtimeout_module);
     AP_DEBUG_ASSERT(cfg != NULL);
-    if (cfg->header_timeout == 0 && cfg->body_timeout == 0) {
+
+    /* For compatibility, handshake timeout is disabled when UNSET (< 0) */
+    if (cfg->handshake.timeout <= 0
+            && cfg->header.timeout == 0
+            && cfg->body.timeout == 0) {
         /* disabled for this vhost */
         return DECLINED;
     }
@@ -369,6 +390,11 @@ static int reqtimeout_init(conn_rec *c)
         ap_set_module_config(c->conn_config, &reqtimeout_module, ccfg);
         ap_add_output_filter(reqtimeout_filter_name, ccfg, NULL, c);
         ap_add_input_filter(reqtimeout_filter_name, ccfg, NULL, c);
+
+        ccfg->type = "handshake";
+        if (cfg->handshake.timeout > 0) {
+            INIT_STAGE(cfg, ccfg, handshake);
+        }
     }
 
     /* we are not handling the connection, we just do initialization */
@@ -393,22 +419,11 @@ static void reqtimeout_before_header(req
     /* (Re)set the state for this new request, but ccfg->socket and
      * ccfg->tmpbb which have the lifetime of the connection.
      */
+    ccfg->type = "header";
     ccfg->timeout_at = 0;
     ccfg->max_timeout_at = 0;
     ccfg->in_keep_alive = (c->keepalives > 0);
-    ccfg->type = "header";
-    if (cfg->header_timeout != UNSET) {
-        ccfg->new_timeout     = cfg->header_timeout;
-        ccfg->new_max_timeout = cfg->header_max_timeout;
-        ccfg->min_rate        = cfg->header_min_rate;
-        ccfg->rate_factor     = cfg->header_rate_factor;
-    }
-    else {
-        ccfg->new_timeout     = MRT_DEFAULT_HEADER_TIMEOUT;
-        ccfg->new_max_timeout = MRT_DEFAULT_HEADER_MAX_TIMEOUT;
-        ccfg->min_rate        = MRT_DEFAULT_HEADER_MIN_RATE;
-        ccfg->rate_factor     = default_header_rate_factor;
-    }
+    INIT_STAGE(cfg, ccfg, header);
 }
 
 static int reqtimeout_before_body(request_rec *r)
@@ -425,60 +440,57 @@ static int reqtimeout_before_body(reques
                                &reqtimeout_module);
     AP_DEBUG_ASSERT(cfg != NULL);
 
+    ccfg->type = "body";
     ccfg->timeout_at = 0;
     ccfg->max_timeout_at = 0;
-    ccfg->type = "body";
     if (r->method_number == M_CONNECT) {
         /* disabled for a CONNECT request */
-        ccfg->new_timeout     = 0;
-    }
-    else if (cfg->body_timeout != UNSET) {
-        ccfg->new_timeout     = cfg->body_timeout;
-        ccfg->new_max_timeout = cfg->body_max_timeout;
-        ccfg->min_rate        = cfg->body_min_rate;
-        ccfg->rate_factor     = cfg->body_rate_factor;
+        ccfg->cur_stage.timeout = 0;
     }
     else {
-        ccfg->new_timeout     = MRT_DEFAULT_BODY_TIMEOUT;
-        ccfg->new_max_timeout = MRT_DEFAULT_BODY_MAX_TIMEOUT;
-        ccfg->min_rate        = MRT_DEFAULT_BODY_MIN_RATE;
-        ccfg->rate_factor     = default_body_rate_factor;
+        INIT_STAGE(cfg, ccfg, body);
     }
     return OK;
 }
 
+#define UNSET_STAGE(cfg, stage) do { \
+    cfg->stage.timeout = UNSET; \
+    cfg->stage.max_timeout = UNSET; \
+    cfg->stage.min_rate = UNSET; \
+} while (0)
+
 static void *reqtimeout_create_srv_config(apr_pool_t *p, server_rec *s)
 {
     reqtimeout_srv_cfg *cfg = apr_pcalloc(p, sizeof(reqtimeout_srv_cfg));
 
-    cfg->header_timeout = UNSET;
-    cfg->header_max_timeout = UNSET;
-    cfg->header_min_rate = UNSET;
-    cfg->body_timeout = UNSET;
-    cfg->body_max_timeout = UNSET;
-    cfg->body_min_rate = UNSET;
+    UNSET_STAGE(cfg, handshake);
+    UNSET_STAGE(cfg, header);
+    UNSET_STAGE(cfg, body);
 
     return cfg;
 }
 
-#define MERGE_INT(cfg, b, a, val) cfg->val = (a->val == UNSET) ? b->val : a->val;
+#define MERGE_INT(cfg, base, add, val) \
+    cfg->val = (add->val == UNSET) ? base->val : add->val
+#define MERGE_STAGE(cfg, base, add, stage) do { \
+    MERGE_INT(cfg, base, add, stage.timeout); \
+    MERGE_INT(cfg, base, add, stage.max_timeout); \
+    MERGE_INT(cfg, base, add, stage.min_rate); \
+    cfg->stage.rate_factor = (cfg->stage.min_rate == UNSET) \
+                             ? base->stage.rate_factor \
+                             : add->stage.rate_factor; \
+} while (0)
+
 static void *reqtimeout_merge_srv_config(apr_pool_t *p, void *base_, void *add_)
 {
     reqtimeout_srv_cfg *base = base_;
     reqtimeout_srv_cfg *add  = add_;
     reqtimeout_srv_cfg *cfg  = apr_pcalloc(p, sizeof(reqtimeout_srv_cfg));
 
-    MERGE_INT(cfg, base, add, header_timeout);
-    MERGE_INT(cfg, base, add, header_max_timeout);
-    MERGE_INT(cfg, base, add, header_min_rate);
-    MERGE_INT(cfg, base, add, body_timeout);
-    MERGE_INT(cfg, base, add, body_max_timeout);
-    MERGE_INT(cfg, base, add, body_min_rate);
-
-    cfg->header_rate_factor = (cfg->header_min_rate == UNSET) ?
-                              base->header_rate_factor : add->header_rate_factor;
-    cfg->body_rate_factor = (cfg->body_min_rate == UNSET) ?
-                            base->body_rate_factor : add->body_rate_factor;
+    MERGE_STAGE(cfg, base, add, handshake);
+    MERGE_STAGE(cfg, base, add, header);
+    MERGE_STAGE(cfg, base, add, body);
+
     return cfg;
 }
 
@@ -506,66 +518,59 @@ static const char *set_reqtimeout_param(
 {
     const char *ret = NULL;
     char *rate_str = NULL, *initial_str, *max_str = NULL;
-    int rate = 0, initial = 0, max = 0;
-    enum { PARAM_HEADER, PARAM_BODY } type;
+    reqtimeout_stage_t *stage;
 
-    if (!strcasecmp(key, "header")) {
-        type = PARAM_HEADER;
+    if (!strcasecmp(key, "handshake")) {
+        stage = &conf->handshake;
+    }
+    else if (!strcasecmp(key, "header")) {
+        stage = &conf->header;
     }
     else if (!strcasecmp(key, "body")) {
-        type = PARAM_BODY;
+        stage = &conf->body;
     }
     else {
         return "Unknown RequestReadTimeout parameter";
     }
 
+    memset(stage, 0, sizeof(*stage));
+
     if ((rate_str = ap_strcasestr(val, ",minrate="))) {
         initial_str = apr_pstrndup(p, val, rate_str - val);
         rate_str += strlen(",minrate=");
-        ret = parse_int(p, rate_str, &rate);
+        ret = parse_int(p, rate_str, &stage->min_rate);
         if (ret)
             return ret;
 
-        if (rate == 0)
+        if (stage->min_rate == 0)
             return "Minimum data rate must be larger than 0";
 
         if ((max_str = strchr(initial_str, '-'))) {
             *max_str++ = '\0';
-            ret = parse_int(p, max_str, &max);
+            ret = parse_int(p, max_str, &stage->max_timeout);
             if (ret)
                 return ret;
         }
 
-        ret = parse_int(p, initial_str, &initial);
+        ret = parse_int(p, initial_str, &stage->timeout);
     }
     else {
         if (ap_strchr_c(val, '-'))
             return "Must set MinRate option if using timeout range";
-        ret = parse_int(p, val, &initial);
+        ret = parse_int(p, val, &stage->timeout);
     }
-
     if (ret)
         return ret;
 
-    if (max && initial >= max) {
+    if (stage->max_timeout && stage->timeout >= stage->max_timeout) {
         return "Maximum timeout must be larger than initial timeout";
     }
 
-    if (type == PARAM_HEADER) {
-        conf->header_timeout = initial;
-        conf->header_max_timeout = max;
-        conf->header_min_rate = rate;
-        if (rate)
-            conf->header_rate_factor = apr_time_from_sec(1) / rate;
-    }
-    else {
-        conf->body_timeout = initial;
-        conf->body_max_timeout = max;
-        conf->body_min_rate = rate;
-        if (rate)
-            conf->body_rate_factor = apr_time_from_sec(1) / rate;
+    if (stage->min_rate) {
+        stage->rate_factor = apr_time_from_sec(1) / stage->min_rate;
     }
-    return ret;
+
+    return NULL;
 }
 
 static const char *set_reqtimeouts(cmd_parms *cmd, void *mconfig,
@@ -603,8 +608,7 @@ static void reqtimeout_hooks(apr_pool_t
 {
     /*
      * mod_ssl is AP_FTYPE_CONNECTION + 5 and mod_reqtimeout needs to
-     * be called before mod_ssl. Otherwise repeated reads during the ssl
-     * handshake can prevent the timeout from triggering.
+     * be called before mod_ssl for the handshake stage to catch SSL traffic.
      */
     ap_register_input_filter(reqtimeout_filter_name, reqtimeout_filter, NULL,
                              AP_FTYPE_CONNECTION + 8);
@@ -621,28 +625,37 @@ static void reqtimeout_hooks(apr_pool_t
      * mod_reqtimeout needs to be called before ap_process_http_request (which
      * is run at APR_HOOK_REALLY_LAST) but after all other protocol modules.
      * This ensures that it only influences normal http connections and not
-     * e.g. mod_ftp. Also, if mod_reqtimeout used the pre_connection hook, it
-     * would be inserted on mod_proxy's backend connections.
+     * e.g. mod_ftp. We still process it first though, for the handshake stage
+     * to work with/before mod_ssl, but since it's disabled by default it won't
+     * influence non-HTTP modules unless configured explicitely. Also, if
+     * mod_reqtimeout used the pre_connection hook, it would be inserted on
+     * mod_proxy's backend connections, and we don't want this.
      */
-    ap_hook_process_connection(reqtimeout_init, NULL, NULL, APR_HOOK_LAST);
+    ap_hook_process_connection(reqtimeout_init, NULL, NULL, APR_HOOK_FIRST);
 
     ap_hook_pre_read_request(reqtimeout_before_header, NULL, NULL,
                              APR_HOOK_MIDDLE);
     ap_hook_post_read_request(reqtimeout_before_body, NULL, NULL,
                               APR_HOOK_MIDDLE);
 
+#if MRT_DEFAULT_HANDSHAKE_MIN_RATE > 0
+    default_handshake_rate_factor = apr_time_from_sec(1) /
+                                    MRT_DEFAULT_HANDSHAKE_MIN_RATE;
+#endif
 #if MRT_DEFAULT_HEADER_MIN_RATE > 0
-    default_header_rate_factor = apr_time_from_sec(1) / MRT_DEFAULT_HEADER_MIN_RATE;
+    default_header_rate_factor = apr_time_from_sec(1) /
+                                 MRT_DEFAULT_HEADER_MIN_RATE;
 #endif
 #if MRT_DEFAULT_BODY_MIN_RATE > 0
-    default_body_rate_factor = apr_time_from_sec(1) / MRT_DEFAULT_BODY_MIN_RATE;
+    default_body_rate_factor = apr_time_from_sec(1) /
+                               MRT_DEFAULT_BODY_MIN_RATE;
 #endif
 }
 
 static const command_rec reqtimeout_cmds[] = {
     AP_INIT_RAW_ARGS("RequestReadTimeout", set_reqtimeouts, NULL, RSRC_CONF,
-                     "Set various timeout parameters for reading request "
-                     "headers and body"),
+                     "Set various timeout parameters for TLS handshake and/or "
+                     "reading request headers and body"),
     {NULL}
 };
 
Index: b/modules/http2/h2_task.c
===================================================================
--- a/modules/http2/h2_task.c
+++ b/modules/http2/h2_task.c
@@ -310,11 +310,9 @@ static apr_status_t h2_filter_slave_in(a
         }
     }
     
-    /* Nothing there, no more data to get. Return APR_EAGAIN on
-     * speculative reads, this is ap_check_pipeline()'s trick to
-     * see if the connection needs closing. */
+    /* Nothing there, no more data to get. Return. */
     if (status == APR_EOF && APR_BRIGADE_EMPTY(task->input.bb)) {
-        return (mode == AP_MODE_SPECULATIVE)? APR_EAGAIN : APR_EOF;
+        return status;
     }
 
     if (trace1) {
@@ -598,7 +596,6 @@ apr_status_t h2_task_do(h2_task *task, a
             slave_id = worker_id; 
         }
         task->c->id = (c->master->id << free_bits)^slave_id;
-        c->keepalive = AP_CONN_KEEPALIVE;
     }
         
     h2_beam_create(&task->output.beam, c->pool, task->stream_id, "output", 
Index: b/docs/manual/mod/mod_reqtimeout.html.en
===================================================================
--- a/docs/manual/mod/mod_reqtimeout.html.en
+++ b/docs/manual/mod/mod_reqtimeout.html.en
@@ -52,10 +52,11 @@
 
     <ol>
       <li>
-        Allow 10 seconds to receive the request including the headers and
-        30 seconds for receiving the request body:
+	Allow for 5 seconds to complete the TLS handshake, 10 seconds to
+	receive the request headers and 30 seconds for receiving the
+	request body:
 
-        <pre class="prettyprint lang-config">RequestReadTimeout header=10 body=30</pre>
+        <pre class="prettyprint lang-config">RequestReadTimeout handshake=5 header=10 body=30</pre>
 
       </li>
 
@@ -71,10 +72,10 @@
       </li>
 
       <li>
-        Allow at least 10 seconds to receive the request including the headers.
+	Allow at least 10 seconds to receive the request headers.
         If the client sends data, increase the timeout by 1 second for every
         500 bytes received. But do not allow more than 30 seconds for the
-        request including the headers:
+        request headers:
 
         <pre class="prettyprint lang-config">RequestReadTimeout header=10-30,MinRate=500</pre>
 
@@ -94,65 +95,67 @@
 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="directive-section"><h2><a name="RequestReadTimeout" id="RequestReadTimeout">RequestReadTimeout</a> <a name="requestreadtimeout" id="requestreadtimeout">Directive</a></h2>
 <table class="directive">
-<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Set timeout values for receiving request headers and body from client.
+<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Set timeout values for completing the TLS handshake, receiving the request headers and/or body from client.
 </td></tr>
 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RequestReadTimeout
+[handshake=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 [header=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 [body=<var>timeout</var>[-<var>maxtimeout</var>][,MinRate=<var>rate</var>]
 </code></td></tr>
-<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>header=20-40,MinRate=500 body=20,MinRate=500</code></td></tr>
+<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>handshake=0 header=20-40,MinRate=500 body=20,MinRate=500</code></td></tr>
 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_reqtimeout</td></tr>
 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Available in version 2.2.15 and later; defaulted to disabled in
-version 2.3.14 and earlier.</td></tr>
+version 2.3.14 and earlier. The <code>handshake</code> stage is available since version 2.4.29.</td></tr>
 </table>
-    <p>This directive can set various timeouts for receiving the request headers
-    and the request body from the client. If the client fails to send headers or
-    body within the configured time, a <code>408 REQUEST TIME OUT</code> error
-    is sent.</p>
+    <p>This directive can set various timeouts for completing the TLS handshake,
+    receiving the request headers and/or the request body from the client.
+    If the client fails to complete each of these stages within the configured
+    time, a <code>408 REQUEST TIME OUT</code> error is sent.</p>
 
-    <p>For SSL virtual hosts, the header timeout values include the time needed
-    to do the initial SSL handshake.  If the user's browser is configured to
+    <p>For SSL virtual hosts, the <code>handshake</code> timeout values is the time
+    needed to do the initial SSL handshake.  If the user's browser is configured to
     query certificate revocation lists and the CRL server is not reachable, the
     initial SSL handshake may take a significant time until the browser gives up
-    waiting for the CRL.  Therefore the header timeout values should not be set
-    to very low values for SSL virtual hosts.
+    waiting for the CRL.  Therefore the <code>handshake</code> timeout should take
+    this possible overhead into consideration for SSL virtual hosts (if necessary).
     The body timeout values include the time needed for SSL renegotiation
     (if necessary).</p>
 
     <p>When an <code class="directive"><a href="../mod/core.html#acceptfilter">AcceptFilter</a></code> is in use
     (usually the case on Linux and FreeBSD), the socket is not sent to the
     server process before at least one byte (or the whole request for
-    <code>httpready</code>) is received. The header timeout configured with
-    <code>RequestReadTimeout</code> is only effective after the server process has
-    received the socket.</p>
+    <code>httpready</code>) is received. The handshake and header timeouts
+    configured with <directive>RequestReadTimeout</directive> are only effective
+    after the server process has received the socket.</p>
 
-    <p>For each of the two timeout types (header or body), there are three ways
-    to specify the timeout:
+    <p>For each of the three timeout stages (handshake, header or body), there are
+    three ways to specify the timeout:
     </p>
 
     <ul>
 
     <li><strong>Fixed timeout value</strong>:<br />
 
-    <div class="example"><p><code><var>type</var>=<var>timeout</var></code></p></div>
+    <div class="example"><p><code><var>stage</var>=<var>timeout</var></code></p></div>
 
-    <p>The time in seconds allowed for reading all of the request headers or
-    body, respectively. A value of 0 means no limit.</p>
+    <p>The time in seconds allowed for completing the whole stage (handshaking,
+    reading all of the request headers or body). A value of 0 means no limit.</p>
     </li>
 
     <li><strong>Disable module for a vhost:</strong>:<br />
 
-    <div class="example"><p><code>header=0 body=0</code></p></div>
+    <div class="example"><p><code>handshake=0 header=0 body=0</code></p></div>
 
-    <p>This disables <code class="module"><a href="../mod/mod_reqtimeout.html">mod_reqtimeout</a></code> completely.</p>
+    <p>This disables <code class="module"><a href="../mod/mod_reqtimeout.html">mod_reqtimeout</a></code> completely (note that
+    <code>handshake=0</code> is the default already and could be omitted).</p>
     </li>
 
     <li><strong>Timeout value that is increased when data is
     received</strong>:<br />
     <div class="example"><p><code>
-    <var>type</var>=<var>timeout</var>,MinRate=<var>data_rate</var>
+    <var>stage</var>=<var>timeout</var>,MinRate=<var>data_rate</var>
     </code></p></div>
 
     <p>Same as above, but whenever data is received, the timeout value is
@@ -163,7 +166,7 @@ version 2.3.14 and earlier.</td></tr>
     <li><strong>Timeout value that is increased when data is received, with an
     upper bound</strong>:<br />
     <div class="example"><p><code>
-    <var>type</var>=<var>timeout</var>-<var>maxtimeout</var>,MinRate=<var>data_rate</var>
+    <var>stage</var>=<var>timeout</var>-<var>maxtimeout</var>,MinRate=<var>data_rate</var>
     </code></p></div>
 
     <p>Same as above, but the timeout will not be increased above the second
@@ -202,4 +205,4 @@ if (typeof(prettyPrint) !== 'undefined')
     prettyPrint();
 }
 //--><!]]></script>
-</body></html>
\ No newline at end of file
+</body></html>
