Skip to content

Commit

Permalink
Merge branch 'sp/maint-smart-http-sans-100-continue'
Browse files Browse the repository at this point in the history
* sp/maint-smart-http-sans-100-continue:
  smart-http: Don't use Expect: 100-Continue
  • Loading branch information
Junio C Hamano committed Feb 28, 2011
2 parents 8e949a4 + 206b099 commit 28afcbf
Showing 1 changed file with 55 additions and 11 deletions.
66 changes: 55 additions & 11 deletions remote-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,59 @@ static size_t rpc_in(const void *ptr, size_t eltsize,
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
Expand All @@ -386,8 +431,13 @@ static int post_rpc(struct rpc_state *rpc)
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);
Expand All @@ -401,7 +451,7 @@ static int post_rpc(struct rpc_state *rpc)
/* 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);
Expand Down Expand Up @@ -475,13 +525,7 @@ static int post_rpc(struct rpc_state *rpc)
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);
Expand Down

0 comments on commit 28afcbf

Please sign in to comment.