Skip to content

Commit 92a209b

Browse files
peffgitster
authored andcommitted
remote-curl: add Transfer-Encoding header only for older curl
As of curl 7.66.0, we don't need to manually specify a "chunked" Transfer-Encoding header. Instead, modern curl deduces the need for it in a POST that has a POSTFIELDSIZE of -1 and uses READFUNCTION rather than POSTFIELDS. That version is recent enough that we can't just drop the header; we need to do so conditionally. Since it's only a single line, it seems like the simplest thing would just be to keep setting it unconditionally (after all, the #ifdefs are much longer than the actual code). But there's another wrinkle: HTTP/2. Curl may choose to use HTTP/2 under the hood if the server supports it. And in that protocol, we do not use the chunked encoding for streaming at all. Most versions of curl handle this just fine by recognizing and removing the header. But there's a regression in curl 8.7.0 and 8.7.1 where it doesn't, and large requests over HTTP/2 are broken (which t5559 notices). That regression has since been fixed upstream, but not yet released. Make the setting of this header conditional, which will let Git work even with those buggy curl versions. And as a bonus, it serves as a reminder that we can eventually clean up the code as we bump the supported curl versions. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c28ee09 commit 92a209b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

git-curl-compat.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@
126126
#define GIT_CURL_HAVE_CURLSSLSET_NO_BACKENDS
127127
#endif
128128

129+
/**
130+
* Versions before curl 7.66.0 (September 2019) required manually setting the
131+
* transfer-encoding for a streaming POST; after that this is handled
132+
* automatically.
133+
*/
134+
#if LIBCURL_VERSION_NUM < 0x074200
135+
#define GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
136+
#endif
137+
129138
/**
130139
* CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR were added in 7.85.0,
131140
* released in August 2022.

remote-curl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "git-compat-util.h"
2+
#include "git-curl-compat.h"
23
#include "config.h"
34
#include "environment.h"
45
#include "gettext.h"
@@ -960,7 +961,9 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
960961
/* The request body is large and the size cannot be predicted.
961962
* We must use chunked encoding to send it.
962963
*/
964+
#ifdef GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
963965
headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
966+
#endif
964967
rpc->initial_buffer = 1;
965968
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
966969
curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);

0 commit comments

Comments
 (0)