From fd9429cc2979233030613a117cda52cc9bf0ce3c Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 7 Aug 2025 11:29:10 +0200 Subject: [PATCH] request: eliminate request `getheader` bool, reverse `header` default Deduce that the transfer response expects headers by the protocol handler implementing `write_resp_hd` callback. This eleminates the `getheader` parameter in the `Curl_xfer_setup_*()` methods. Add an implementation to RTSP for `write_resp_hd`, joining the HTTP protocol in the only handlers having it. Reverse the default of request's `header` bit that signals that headers are expected. Default is now FALSE, set to TRUE when setting up the transfer by presence of `write_resp_hd` in the protocol handler. Closes #18218 --- lib/curl_rtmp.c | 2 +- lib/dict.c | 6 +++--- lib/ftp.c | 3 +-- lib/gopher.c | 2 +- lib/http.c | 2 +- lib/imap.c | 2 +- lib/openldap.c | 2 +- lib/pop3.c | 2 +- lib/request.c | 3 +-- lib/request.h | 1 - lib/rtsp.c | 18 +++++++++++++++--- lib/transfer.c | 28 +++++++++++----------------- lib/transfer.h | 11 ++++------- lib/vssh/libssh.c | 4 ++-- lib/vssh/libssh2.c | 4 ++-- lib/vssh/wolfssh.c | 2 +- 16 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c index 07e0eeba26..b178dff845 100644 --- a/lib/curl_rtmp.c +++ b/lib/curl_rtmp.c @@ -299,7 +299,7 @@ static CURLcode rtmp_do(struct Curl_easy *data, bool *done) Curl_xfer_setup_send(data, FIRSTSOCKET); } else - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); *done = TRUE; return CURLE_OK; } diff --git a/lib/dict.c b/lib/dict.c index b8ede7848d..819584f284 100644 --- a/lib/dict.c +++ b/lib/dict.c @@ -242,7 +242,7 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) failf(data, "Failed sending DICT request"); goto error; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); } else if(curl_strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) || curl_strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) || @@ -283,7 +283,7 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) failf(data, "Failed sending DICT request"); goto error; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); } else { @@ -305,7 +305,7 @@ static CURLcode dict_do(struct Curl_easy *data, bool *done) goto error; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); } } diff --git a/lib/ftp.c b/lib/ftp.c index d9539c7fd4..f088054b2d 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -551,8 +551,7 @@ static CURLcode ftp_initiate_transfer(struct Curl_easy *data, } else { /* FTP download, shutdown, do not ignore errors */ - Curl_xfer_setup_recv(data, SECONDARYSOCKET, - ftpc->retr_size_saved, FALSE); + Curl_xfer_setup_recv(data, SECONDARYSOCKET, ftpc->retr_size_saved); Curl_xfer_set_shutdown(data, TRUE, FALSE); } diff --git a/lib/gopher.c b/lib/gopher.c index 9ac3cca3e1..93db85e9d0 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -240,7 +240,7 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(result) return result; - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); return CURLE_OK; } #endif /* CURL_DISABLE_GOPHER */ diff --git a/lib/http.c b/lib/http.c index 5e36decdd4..972d9af23e 100644 --- a/lib/http.c +++ b/lib/http.c @@ -2415,7 +2415,7 @@ static CURLcode http_req_complete(struct Curl_easy *data, out: if(!result) { /* setup variables for the upcoming transfer */ - Curl_xfer_setup_sendrecv(data, FIRSTSOCKET, -1, TRUE); + Curl_xfer_setup_sendrecv(data, FIRSTSOCKET, -1); } return result; } diff --git a/lib/imap.c b/lib/imap.c index d8f46a034c..7e6b132ba0 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -1347,7 +1347,7 @@ static CURLcode imap_state_fetch_resp(struct Curl_easy *data, else { /* IMAP download */ data->req.maxdownload = size; - Curl_xfer_setup_recv(data, FIRSTSOCKET, size, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, size); } } else { diff --git a/lib/openldap.c b/lib/openldap.c index c10f07220f..1b32e12b68 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -993,7 +993,7 @@ static CURLcode oldap_do(struct Curl_easy *data, bool *done) } lr->msgid = msgid; - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); *done = TRUE; out: diff --git a/lib/pop3.c b/lib/pop3.c index 9417bb5fe8..508f8faed3 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -1116,7 +1116,7 @@ static CURLcode pop3_state_command_resp(struct Curl_easy *data, if(pop3->transfer == PPTRANSFER_BODY) { /* POP3 download */ - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); if(pp->overflow) { /* The recv buffer contains data that is actually body content so send diff --git a/lib/request.c b/lib/request.c index 7e4082bee3..733e3e9294 100644 --- a/lib/request.c +++ b/lib/request.c @@ -62,7 +62,7 @@ CURLcode Curl_req_soft_reset(struct SingleRequest *req, req->shutdown = FALSE; req->bytecount = 0; req->writebytecount = 0; - req->header = TRUE; /* assume header */ + req->header = FALSE; req->headerline = 0; req->headerbytecount = 0; req->allheadercount = 0; @@ -161,7 +161,6 @@ void Curl_req_hard_reset(struct SingleRequest *req, struct Curl_easy *data) req->chunk = FALSE; req->ignore_cl = FALSE; req->upload_chunky = FALSE; - req->getheader = FALSE; req->no_body = data->set.opt_no_body; req->authneg = FALSE; req->shutdown = FALSE; diff --git a/lib/request.h b/lib/request.h index 74d9f53439..bce34de8ba 100644 --- a/lib/request.h +++ b/lib/request.h @@ -123,7 +123,6 @@ struct SingleRequest { BIT(ignore_cl); /* ignore content-length */ BIT(upload_chunky); /* set TRUE if we are doing chunked transfer-encoding on upload */ - BIT(getheader); /* TRUE if header parsing is wanted */ BIT(no_body); /* the response has no body */ BIT(authneg); /* TRUE when the auth phase has started, which means that we are creating a request with an auth header, diff --git a/lib/rtsp.c b/lib/rtsp.c index 153b98ea39..dbe3e63cf3 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -100,6 +100,10 @@ static CURLcode rtsp_rtp_write_resp(struct Curl_easy *data, const char *buf, size_t blen, bool is_eos); +static CURLcode rtsp_rtp_write_resp_hd(struct Curl_easy *data, + const char *buf, + size_t blen, + bool is_eos); static CURLcode rtsp_setup_connection(struct Curl_easy *data, struct connectdata *conn); @@ -141,7 +145,7 @@ const struct Curl_handler Curl_handler_rtsp = { ZERO_NULL, /* perform_pollset */ ZERO_NULL, /* disconnect */ rtsp_rtp_write_resp, /* write_resp */ - ZERO_NULL, /* write_resp_hd */ + rtsp_rtp_write_resp_hd, /* write_resp_hd */ rtsp_conncheck, /* connection_check */ ZERO_NULL, /* attach connection */ Curl_http_follow, /* follow */ @@ -370,7 +374,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) } if(rtspreq == RTSPREQ_RECEIVE) { - Curl_xfer_setup_recv(data, FIRSTSOCKET, -1, TRUE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); goto out; } @@ -636,7 +640,7 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) if(result) goto out; - Curl_xfer_setup_sendrecv(data, FIRSTSOCKET, -1, TRUE); + Curl_xfer_setup_sendrecv(data, FIRSTSOCKET, -1); /* issue the request */ result = Curl_req_send(data, &req_buffer, httpversion); @@ -935,6 +939,14 @@ out: return result; } +static CURLcode rtsp_rtp_write_resp_hd(struct Curl_easy *data, + const char *buf, + size_t blen, + bool is_eos) +{ + return rtsp_rtp_write_resp(data, buf, blen, is_eos); +} + static CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, size_t len) { diff --git a/lib/transfer.c b/lib/transfer.c index 76b7a8964b..50f621056f 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -721,8 +721,7 @@ static void xfer_setup( struct Curl_easy *data, /* transfer */ int send_idx, /* sockindex to send on or -1 */ int recv_idx, /* sockindex to receive on or -1 */ - curl_off_t recv_size, /* how much to receive, -1 if unknown */ - bool getheader /* TRUE if header parsing is wanted */ + curl_off_t recv_size /* how much to receive, -1 if unknown */ ) { struct SingleRequest *k = &data->req; @@ -738,10 +737,10 @@ static void xfer_setup( conn->send_idx = send_idx; conn->recv_idx = recv_idx; - k->getheader = getheader; /* without receiving, there should be not recv_size */ DEBUGASSERT((conn->recv_idx >= 0) || (recv_size == -1)); k->size = recv_size; + k->header = !!conn->handler->write_resp_hd; /* by default, we do not shutdown at the end of the transfer */ k->shutdown = FALSE; k->shutdown_err_ignore = FALSE; @@ -749,14 +748,11 @@ static void xfer_setup( /* The code sequence below is placed in this function just because all necessary input is not always known in do_complete() as this function may be called after that */ - if(!k->getheader) { - k->header = FALSE; - if(recv_size > 0) - Curl_pgrsSetDownloadSize(data, recv_size); - } + if(!k->header && (recv_size > 0)) + Curl_pgrsSetDownloadSize(data, recv_size); /* we want header and/or body, if neither then do not do this! */ - if(k->getheader || !data->req.no_body) { + if(conn->handler->write_resp_hd || !data->req.no_body) { if(conn->recv_idx != -1) k->keepon |= KEEP_RECV; @@ -771,29 +767,27 @@ static void xfer_setup( void Curl_xfer_setup_nop(struct Curl_easy *data) { - xfer_setup(data, -1, -1, -1, FALSE); + xfer_setup(data, -1, -1, -1); } void Curl_xfer_setup_sendrecv(struct Curl_easy *data, int sockindex, - curl_off_t recv_size, - bool getheader) + curl_off_t recv_size) { - xfer_setup(data, sockindex, sockindex, recv_size, getheader); + xfer_setup(data, sockindex, sockindex, recv_size); } void Curl_xfer_setup_send(struct Curl_easy *data, int sockindex) { - xfer_setup(data, sockindex, -1, -1, FALSE); + xfer_setup(data, sockindex, -1, -1); } void Curl_xfer_setup_recv(struct Curl_easy *data, int sockindex, - curl_off_t recv_size, - bool getheader) + curl_off_t recv_size) { - xfer_setup(data, -1, sockindex, recv_size, getheader); + xfer_setup(data, -1, sockindex, recv_size); } void Curl_xfer_set_shutdown(struct Curl_easy *data, diff --git a/lib/transfer.h b/lib/transfer.h index 095c94fe27..91a81e52e8 100644 --- a/lib/transfer.h +++ b/lib/transfer.h @@ -72,11 +72,10 @@ void Curl_xfer_setup_send(struct Curl_easy *data, int sockindex); /* The transfer receives data on the given socket index, the - * amount to receive (or -1 if unknown) and if headers are expected */ + * amount to receive (or -1 if unknown). */ void Curl_xfer_setup_recv(struct Curl_easy *data, int sockindex, - curl_off_t recv_size, - bool getheader); + curl_off_t recv_size); /* *After* Curl_xfer_setup_xxx(), tell the transfer to shutdown the * connection at the end. Let the transfer either fail or ignore any @@ -87,13 +86,11 @@ void Curl_xfer_set_shutdown(struct Curl_easy *data, /** * The transfer will use socket 1 to send/recv. `recv_size` is - * the amount to receive or -1 if unknown. `getheader` indicates - * response header processing is expected. + * the amount to receive or -1 if unknown. */ void Curl_xfer_setup_sendrecv(struct Curl_easy *data, int sockindex, - curl_off_t recv_size, - bool getheader); + curl_off_t recv_size); /** * Multi has set transfer to DONE. Last chance to trigger diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index f04d5fe320..8c366aafae 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -1423,7 +1423,7 @@ static int myssh_in_SFTP_DOWNLOAD_STAT(struct Curl_easy *data, myssh_to(data, sshc, SSH_STOP); return rc; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size); /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->send_idx = 0; @@ -2279,7 +2279,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, /* download data */ bytecount = ssh_scp_request_get_size(sshc->scp_session); data->req.maxdownload = (curl_off_t) bytecount; - Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); /* not set by Curl_xfer_setup to preserve keepon bits */ conn->send_idx = 0; diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 089a7af020..f6985ed251 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -1540,7 +1540,7 @@ sftp_download_stat(struct Curl_easy *data, myssh_state(data, sshc, SSH_STOP); return CURLE_OK; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size); /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->send_idx = 0; @@ -2460,7 +2460,7 @@ static CURLcode ssh_state_scp_download_init(struct Curl_easy *data, /* download data */ bytecount = (curl_off_t)sb.st_size; data->req.maxdownload = (curl_off_t)sb.st_size; - Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, bytecount); /* not set by Curl_xfer_setup to preserve keepon bits */ data->conn->send_idx = 0; diff --git a/lib/vssh/wolfssh.c b/lib/vssh/wolfssh.c index 7696545a07..556eda0cb5 100644 --- a/lib/vssh/wolfssh.c +++ b/lib/vssh/wolfssh.c @@ -816,7 +816,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, wssh_state(data, sshc, SSH_STOP); break; } - Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size, FALSE); + Curl_xfer_setup_recv(data, FIRSTSOCKET, data->req.size); /* not set by Curl_xfer_setup to preserve keepon bits */ conn->send_idx = 0; -- 2.47.3