]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote-curl: add Transfer-Encoding header only for older curl
authorJeff King <peff@peff.net>
Fri, 5 Apr 2024 20:04:51 +0000 (16:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2024 21:45:19 +0000 (14:45 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-curl-compat.h
remote-curl.c

index fd96b3cdffdb6cd11b429bcada40663e80dbebc9..e1d0bdd273501f98a186961f6eb00aa537953052 100644 (file)
 #define GIT_CURL_HAVE_CURLSSLSET_NO_BACKENDS
 #endif
 
+/**
+ * Versions before curl 7.66.0 (September 2019) required manually setting the
+ * transfer-encoding for a streaming POST; after that this is handled
+ * automatically.
+ */
+#if LIBCURL_VERSION_NUM < 0x074200
+#define GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
+#endif
+
 /**
  * CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR were added in 7.85.0,
  * released in August 2022.
index 1161dc7fed689259141ae2eb5403d84b906027d3..603c11ba66724626c116333aeeb2d718097cc8ae 100644 (file)
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "git-curl-compat.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -960,7 +961,9 @@ retry:
                /* The request body is large and the size cannot be predicted.
                 * We must use chunked encoding to send it.
                 */
+#ifdef GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
                headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
+#endif
                rpc->initial_buffer = 1;
                curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
                curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);