]> git.ipfire.org Git - thirdparty/git.git/blobdiff - remote-curl.c
The fifth batch
[thirdparty/git.git] / remote-curl.c
index 31b02b8840969d17c34715fb3b902c6d2b4a4f2d..cae98384dae637ec6c235c15ea7236aec65de317 100644 (file)
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
 #include "git-compat-util.h"
+#include "git-curl-compat.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -888,7 +889,7 @@ static curl_off_t xcurl_off_t(size_t len)
 static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_received)
 {
        struct active_request_slot *slot;
 static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_received)
 {
        struct active_request_slot *slot;
-       struct curl_slist *headers = http_copy_default_headers();
+       struct curl_slist *headers = NULL;
        int use_gzip = rpc->gzip_request;
        char *gzip_body = NULL;
        size_t gzip_size = 0;
        int use_gzip = rpc->gzip_request;
        char *gzip_body = NULL;
        size_t gzip_size = 0;
@@ -921,20 +922,24 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
                do {
                        err = probe_rpc(rpc, &results);
                        if (err == HTTP_REAUTH)
                do {
                        err = probe_rpc(rpc, &results);
                        if (err == HTTP_REAUTH)
-                               credential_fill(&http_auth);
+                               credential_fill(&http_auth, 0);
                } while (err == HTTP_REAUTH);
                if (err != HTTP_OK)
                        return -1;
 
                } while (err == HTTP_REAUTH);
                if (err != HTTP_OK)
                        return -1;
 
-               if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
+               if (results.auth_avail & CURLAUTH_GSSNEGOTIATE || http_auth.authtype)
                        needs_100_continue = 1;
        }
 
                        needs_100_continue = 1;
        }
 
+retry:
+       headers = http_copy_default_headers();
        headers = curl_slist_append(headers, rpc->hdr_content_type);
        headers = curl_slist_append(headers, rpc->hdr_accept);
        headers = curl_slist_append(headers, needs_100_continue ?
                "Expect: 100-continue" : "Expect:");
 
        headers = curl_slist_append(headers, rpc->hdr_content_type);
        headers = curl_slist_append(headers, rpc->hdr_accept);
        headers = curl_slist_append(headers, needs_100_continue ?
                "Expect: 100-continue" : "Expect:");
 
+       headers = http_append_auth_header(&http_auth, headers);
+
        /* Add Accept-Language header */
        if (rpc->hdr_accept_language)
                headers = curl_slist_append(headers, rpc->hdr_accept_language);
        /* Add Accept-Language header */
        if (rpc->hdr_accept_language)
                headers = curl_slist_append(headers, rpc->hdr_accept_language);
@@ -943,7 +948,6 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
        if (rpc->protocol_header)
                headers = curl_slist_append(headers, rpc->protocol_header);
 
        if (rpc->protocol_header)
                headers = curl_slist_append(headers, rpc->protocol_header);
 
-retry:
        slot = get_active_slot();
 
        curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
        slot = get_active_slot();
 
        curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
@@ -955,7 +959,9 @@ retry:
                /* The request body is large and the size cannot be predicted.
                 * We must use chunked encoding to send it.
                 */
                /* 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");
                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);
                rpc->initial_buffer = 1;
                curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
                curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
@@ -1038,7 +1044,8 @@ retry:
        rpc->any_written = 0;
        err = run_slot(slot, NULL);
        if (err == HTTP_REAUTH && !large_request) {
        rpc->any_written = 0;
        err = run_slot(slot, NULL);
        if (err == HTTP_REAUTH && !large_request) {
-               credential_fill(&http_auth);
+               credential_fill(&http_auth, 0);
+               curl_slist_free_all(headers);
                goto retry;
        }
        if (err != HTTP_OK)
                goto retry;
        }
        if (err != HTTP_OK)