conncontrol: reuse handling

Add protocol handler flag `PROTOPT_CONN_REUSE` to indicate that the
protocol allows reusing connections for other tranfers. Add that
to all handlers that support it.

Create connections with `conn->bits.close = FALSE` and remove all
the `connkeep()` calls in protocol handlers setup/connect implementations.
`PROTOPT_CONN_REUSE` assures that the default behaviour applies
at the end of a transfer without need to juggle the close bit.

`conn->bits.close` now serves as an additional indication that a
connection cannot be reused. Only protocol handles that allow
reuse need to set it to override the default behaviour.

Remove all `connclose()` and `connkeep()` calls from connection
filters. Filters should not modify connection flags. They are
supposed to run in eyeballing situations where a filter is just
one of many determining the outcome.

Fix http response header handling to only honour `Connection: close`
for HTTP/1.x versions.

Closes #19333
This commit is contained in:
Stefan Eissing 2025-11-03 13:12:50 +01:00 committed by Daniel Stenberg
parent a9e7a027ed
commit feea968512
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
21 changed files with 93 additions and 114 deletions

View file

@ -142,7 +142,8 @@ const struct Curl_handler Curl_handler_http = {
CURLPROTO_HTTP, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_CREDSPERREQUEST | /* flags */
PROTOPT_USERPWDCTRL
PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE
};
#ifdef USE_SSL
@ -172,7 +173,7 @@ const struct Curl_handler Curl_handler_https = {
CURLPROTO_HTTPS, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN | /* flags */
PROTOPT_USERPWDCTRL
PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE
};
#endif
@ -220,7 +221,6 @@ CURLcode Curl_http_setup_conn(struct Curl_easy *data,
{
/* allocate the HTTP-specific struct for the Curl_easy, only to survive
during this request */
connkeep(conn, "HTTP default");
if(data->state.http_neg.wanted == CURL_HTTP_V3x) {
/* only HTTP/3, needs to work */
CURLcode result = Curl_conn_may_http3(data, conn, conn->transport_wanted);
@ -1548,12 +1548,6 @@ Curl_compareheader(const char *headerline, /* line to check */
*/
CURLcode Curl_http_connect(struct Curl_easy *data, bool *done)
{
struct connectdata *conn = data->conn;
/* We default to persistent connections. We set this already in this connect
function to make the reuse checks properly be able to check this bit. */
connkeep(conn, "HTTP default");
return Curl_conn_connect(data, FIRSTSOCKET, FALSE, done);
}
@ -3257,14 +3251,15 @@ static CURLcode http_header_c(struct Curl_easy *data,
}
return CURLE_OK;
}
if(HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) {
if((k->httpversion < 20) &&
HD_IS_AND_SAYS(hd, hdlen, "Connection:", "close")) {
/*
* [RFC 2616, section 8.1.2.1]
* "Connection: close" is HTTP/1.1 language and means that
* the connection will close when this request has been
* served.
*/
streamclose(conn, "Connection: close used");
connclose(conn, "Connection: close used");
return CURLE_OK;
}
if((k->httpversion == 10) &&