remote-curl: reset headers on new request

When we retry a post_rpc request, we currently reuse the same headers as before. In the future, we'd like to be able to modify them based on the result we get back, so let's reset them on each retry so we can avoid sending potentially duplicate headers if the values change. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 17, 2024 at 00:02 UTC 90765ea81eab98cd8f26c406588f5a6ea6f4fe82
1 file changed +4 -2
remote-curl.c
+4 -2
@@ -893,7 +893,7 @@ static curl_off_t xcurl_off_t(size_t len)
893 static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_received)
894 {
895 struct active_request_slot *slot;
896 - struct curl_slist *headers = http_copy_default_headers();
896 + struct curl_slist *headers = NULL;
897 int use_gzip = rpc->gzip_request;
898 char *gzip_body = NULL;
899 size_t gzip_size = 0;
@@ -935,6 +935,8 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
935 needs_100_continue = 1;
936 }
937
938 +retry:
939 + headers = http_copy_default_headers();
940 headers = curl_slist_append(headers, rpc->hdr_content_type);
941 headers = curl_slist_append(headers, rpc->hdr_accept);
942 headers = curl_slist_append(headers, needs_100_continue ?
@@ -948,7 +950,6 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
950 if (rpc->protocol_header)
951 headers = curl_slist_append(headers, rpc->protocol_header);
952
951 -retry:
953 slot = get_active_slot();
954
955 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
@@ -1044,6 +1045,7 @@ retry:
1045 err = run_slot(slot, NULL);
1046 if (err == HTTP_REAUTH && !large_request) {
1047 credential_fill(&http_auth);
1048 + curl_slist_free_all(headers);
1049 goto retry;
1050 }
1051 if (err != HTTP_OK)