@@ -176,6 +176,7 @@ static int is_mpm_running(void)
176176AP_DECLARE (int ) ap_set_keepalive (request_rec * r )
177177{
178178 int ka_sent = 0 ;
179+ int left = r -> server -> keep_alive_max - r -> connection -> keepalives ;
179180 int wimpy = ap_find_token (r -> pool ,
180181 apr_table_get (r -> headers_out , "Connection" ),
181182 "close" );
@@ -221,7 +222,7 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r)
221222 && r -> server -> keep_alive
222223 && (r -> server -> keep_alive_timeout > 0 )
223224 && ((r -> server -> keep_alive_max == 0 )
224- || (r -> server -> keep_alive_max > r -> connection -> keepalives ))
225+ || (left > 0 ))
225226 && !ap_status_drops_connection (r -> status )
226227 && !wimpy
227228 && !ap_find_token (r -> pool , conn , "close" )
@@ -230,7 +231,6 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r)
230231 && ((ka_sent = ap_find_token (r -> pool , conn , "keep-alive" ))
231232 || (r -> proto_num >= HTTP_VERSION (1 ,1 )))
232233 && is_mpm_running ()) {
233- int left = r -> server -> keep_alive_max - r -> connection -> keepalives ;
234234
235235 r -> connection -> keepalive = AP_CONN_KEEPALIVE ;
236236 r -> connection -> keepalives ++ ;
@@ -266,6 +266,16 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r)
266266 apr_table_mergen (r -> headers_out , "Connection" , "close" );
267267 }
268268
269+ /*
270+ * If we had previously been a keepalive connection and this
271+ * is the last one, then bump up the number of keepalives
272+ * we've had
273+ */
274+ if ((r -> connection -> keepalive != AP_CONN_CLOSE )
275+ && r -> server -> keep_alive_max
276+ && !left ) {
277+ r -> connection -> keepalives ++ ;
278+ }
269279 r -> connection -> keepalive = AP_CONN_CLOSE ;
270280
271281 return 0 ;
0 commit comments