Merge branch 'sp/maint-smart-http-sans-100-continue'
authorJunio C Hamano <gitster@pobox.com>
Mon, 28 Feb 2011 05:58:29 +0000 (21:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Feb 2011 05:58:29 +0000 (21:58 -0800)
* sp/maint-smart-http-sans-100-continue:
smart-http: Don't use Expect: 100-Continue

1  2 
remote-curl.c
diff --combined remote-curl.c
index 04d4813e4183c675b54aba942cd078d8ff632053,256326afb5c720bf7451e227c838701d4fd75d0c..d0fb0a044a85ec6169c4623c7c2ab2143dbb5784
@@@ -9,7 -9,8 +9,7 @@@
  #include "sideband.h"
  
  static struct remote *remote;
 -static const char *url;
 -static struct walker *walker;
 +static const char *url; /* always ends with a trailing slash */
  
  struct options {
        int verbosity;
  };
  static struct options options;
  
 -static void init_walker(void)
 -{
 -      if (!walker)
 -              walker = get_http_walker(url, remote);
 -}
 -
  static int set_option(const char *name, const char *value)
  {
        if (!strcmp(name, "verbosity")) {
@@@ -101,7 -108,7 +101,7 @@@ static struct discovery* discover_refs(
                return last;
        free_discovery(last);
  
 -      strbuf_addf(&buffer, "%s/info/refs", url);
 +      strbuf_addf(&buffer, "%sinfo/refs", url);
        if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
                is_http = 1;
                if (!strchr(url, '?'))
        }
        refs_url = strbuf_detach(&buffer, NULL);
  
 -      init_walker();
        http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
  
        /* try again with "plain" url (no ? or & appended) */
                strbuf_reset(&buffer);
  
                proto_git_candidate = 0;
 -              strbuf_addf(&buffer, "%s/info/refs", url);
 +              strbuf_addf(&buffer, "%sinfo/refs", url);
                refs_url = strbuf_detach(&buffer, NULL);
  
                http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
        case HTTP_MISSING_TARGET:
                die("%s not found: did you run git update-server-info on the"
                    " server?", refs_url);
 +      case HTTP_NOAUTH:
 +              die("Authentication failed");
        default:
                http_error(refs_url, http_ret);
                die("HTTP request failed");
@@@ -244,8 -250,9 +244,8 @@@ static struct ref *parse_info_refs(stru
                i++;
        }
  
 -      init_walker();
        ref = alloc_ref("HEAD");
 -      if (!walker->fetch_ref(walker, ref) &&
 +      if (!http_fetch_ref(url, ref) &&
            !resolve_remote_symref(ref, refs)) {
                ref->next = refs;
                refs = ref;
@@@ -356,14 -363,59 +356,59 @@@ static size_t rpc_in(const void *ptr, s
        return size;
  }
  
+ static int run_slot(struct active_request_slot *slot)
+ {
+       int err = 0;
+       struct slot_results results;
+       slot->results = &results;
+       slot->curl_result = curl_easy_perform(slot->curl);
+       finish_active_slot(slot);
+       if (results.curl_result != CURLE_OK) {
+               err |= error("RPC failed; result=%d, HTTP code = %ld",
+                       results.curl_result, results.http_code);
+       }
+       return err;
+ }
+ static int probe_rpc(struct rpc_state *rpc)
+ {
+       struct active_request_slot *slot;
+       struct curl_slist *headers = NULL;
+       struct strbuf buf = STRBUF_INIT;
+       int err;
+       slot = get_active_slot();
+       headers = curl_slist_append(headers, rpc->hdr_content_type);
+       headers = curl_slist_append(headers, rpc->hdr_accept);
+       curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
+       curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
+       curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
+       curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
+       curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
+       curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
+       curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
+       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
+       curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
+       err = run_slot(slot);
+       curl_slist_free_all(headers);
+       strbuf_release(&buf);
+       return err;
+ }
  static int post_rpc(struct rpc_state *rpc)
  {
        struct active_request_slot *slot;
-       struct slot_results results;
        struct curl_slist *headers = NULL;
        int use_gzip = rpc->gzip_request;
        char *gzip_body = NULL;
-       int err = 0, large_request = 0;
+       int err, large_request = 0;
  
        /* Try to load the entire request, if we can fit it into the
         * allocated buffer space we can use HTTP/1.0 and avoid the
                rpc->len += n;
        }
  
+       if (large_request) {
+               err = probe_rpc(rpc);
+               if (err)
+                       return err;
+       }
        slot = get_active_slot();
-       slot->results = &results;
  
        curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
        curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
                /* The request body is large and the size cannot be predicted.
                 * We must use chunked encoding to send it.
                 */
-               headers = curl_slist_append(headers, "Expect: 100-continue");
+               headers = curl_slist_append(headers, "Expect:");
                headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
                rpc->initial_buffer = 1;
                curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
        curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
  
-       slot->curl_result = curl_easy_perform(slot->curl);
-       finish_active_slot(slot);
-       if (results.curl_result != CURLE_OK) {
-               err |= error("RPC failed; result=%d, HTTP code = %ld",
-                       results.curl_result, results.http_code);
-       }
+       err = run_slot(slot);
  
        curl_slist_free_all(headers);
        free(gzip_body);
@@@ -495,6 -546,7 +539,6 @@@ static int rpc_service(struct rpc_stat
        struct child_process client;
        int err = 0;
  
 -      init_walker();
        memset(&client, 0, sizeof(client));
        client.in = -1;
        client.out = -1;
        rpc->out = client.out;
        strbuf_init(&rpc->result, 0);
  
 -      strbuf_addf(&buf, "%s/%s", url, svc);
 +      strbuf_addf(&buf, "%s%s", url, svc);
        rpc->service_url = strbuf_detach(&buf, NULL);
  
        strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
                rpc->len = n;
                err |= post_rpc(rpc);
        }
 -      strbuf_read(&rpc->result, client.out, 0);
  
        close(client.in);
 -      close(client.out);
        client.in = -1;
 +      strbuf_read(&rpc->result, client.out, 0);
 +
 +      close(client.out);
        client.out = -1;
  
        err |= finish_command(&client);
  
  static int fetch_dumb(int nr_heads, struct ref **to_fetch)
  {
 +      struct walker *walker;
        char **targets = xmalloc(nr_heads * sizeof(char*));
        int ret, i;
  
        for (i = 0; i < nr_heads; i++)
                targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
  
 -      init_walker();
 +      walker = get_http_walker(url);
        walker->get_all = 1;
        walker->get_tree = 1;
        walker->get_history = 1;
        walker->get_verbosely = options.verbosity >= 3;
        walker->get_recover = 0;
        ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
 +      walker_free(walker);
  
        for (i = 0; i < nr_heads; i++)
                free(targets[i]);
@@@ -801,15 -850,11 +845,15 @@@ int main(int argc, const char **argv
        remote = remote_get(argv[1]);
  
        if (argc > 2) {
 -              url = argv[2];
 +              end_url_with_slash(&buf, argv[2]);
        } else {
 -              url = remote->url[0];
 +              end_url_with_slash(&buf, remote->url[0]);
        }
  
 +      url = strbuf_detach(&buf, NULL);
 +
 +      http_init(remote);
 +
        do {
                if (strbuf_getline(&buf, stdin, '\n') == EOF)
                        break;
                }
                strbuf_reset(&buf);
        } while (1);
 +
 +      http_cleanup();
 +
        return 0;
  }