From 92eadbea0cde9f7c2cbcd393414ea9e771c9ebf5 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Fri, 27 Aug 2004 23:44:41 +0000 Subject: [PATCH] Make ap_set_keepalive more statefully aware, allowing it to be called multiple times (to correctly set keepalive) but not increment keepalives when not needed. This allows us to handle a special case where we need to discard body content "early" PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@104871 13f79535-47bb-0310-9956-ffa450edef68 --- src/CHANGES | 5 +++-- src/main/http_protocol.c | 13 ++++++++++++- src/main/http_request.c | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/CHANGES b/src/CHANGES index 702264d01dd..de864cdc857 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -24,9 +24,10 @@ Changes with Apache 1.3.32 was not checked properly. This affects mod_usertrack and core. PR 28218. [André Malo] - *) No longer breaks mod_dav, frontpage and others. Backs out - a patch which prevented discarding the request body for requests + *) No longer breaks mod_dav, frontpage and others. Repair a patch + in 1.3.31 which prevented discarding the request body for requests that will be keptalive but are not currently keptalive. PR 29237. + [Jim Jagielski] *) COMPATIBILITY: Added new compile-time flag: UCN_OFF_HONOR_PHYSICAL_PORT. It controls how UseCanonicalName Off determines the port value if diff --git a/src/main/http_protocol.c b/src/main/http_protocol.c index a1dab39b767..8211a446605 100644 --- a/src/main/http_protocol.c +++ b/src/main/http_protocol.c @@ -391,6 +391,7 @@ API_EXPORT(int) ap_set_keepalive(request_rec *r) int wimpy = ap_find_token(r->pool, ap_table_get(r->headers_out, "Connection"), "close"); const char *conn = ap_table_get(r->headers_in, "Connection"); + const char *herebefore = ap_table_get(r->notes, "ap_set_keepalive-called"); /* The following convoluted conditional determines whether or not * the current connection should remain persistent after this response @@ -442,7 +443,17 @@ API_EXPORT(int) ap_set_keepalive(request_rec *r) int left = r->server->keep_alive_max - r->connection->keepalives; r->connection->keepalive = 1; - r->connection->keepalives++; + /* + * ap_set_keepalive could be called multiple times (eg: in + * ap_die() followed by ap_send_http_header()) during this + * one single request. To ensure that we don't incorrectly + * increment the keepalives counter for each call, we + * use notes to store a state flag. + */ + if (!herebefore) { + r->connection->keepalives++; + ap_table_setn(r->notes, "ap_set_keepalive-called", "1"); + } /* If they sent a Keep-Alive token, send one back */ if (ka_sent) { diff --git a/src/main/http_request.c b/src/main/http_request.c index ef4ed74a7e6..64f5914800d 100644 --- a/src/main/http_request.c +++ b/src/main/http_request.c @@ -1050,13 +1050,19 @@ API_EXPORT(void) ap_die(int type, request_rec *r) r->status = HTTP_PROXY_AUTHENTICATION_REQUIRED; } + /* + * We need to ensure that r->connection->keepalive is valid in + * order to determine if we can discard the request body below. + */ + ap_set_keepalive(r); + /* * If we want to keep the connection, be sure that the request body * (if any) has been read. */ if ((r->status != HTTP_NOT_MODIFIED) && (r->status != HTTP_NO_CONTENT) && !ap_status_drops_connection(r->status) - && r->connection && (r->connection->keepalive != -1)) { + && r->connection && (r->connection->keepalive > 0)) { (void) ap_discard_request_body(r); } -- 2.47.2