Skip to content

Commit 28afcbf

Browse files
committed
Merge branch 'sp/maint-smart-http-sans-100-continue'
* sp/maint-smart-http-sans-100-continue: smart-http: Don't use Expect: 100-Continue
2 parents 8e949a4 + 206b099 commit 28afcbf

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

remote-curl.c

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,59 @@ static size_t rpc_in(const void *ptr, size_t eltsize,
356356
return size;
357357
}
358358

359+
static int run_slot(struct active_request_slot *slot)
360+
{
361+
int err = 0;
362+
struct slot_results results;
363+
364+
slot->results = &results;
365+
slot->curl_result = curl_easy_perform(slot->curl);
366+
finish_active_slot(slot);
367+
368+
if (results.curl_result != CURLE_OK) {
369+
err |= error("RPC failed; result=%d, HTTP code = %ld",
370+
results.curl_result, results.http_code);
371+
}
372+
373+
return err;
374+
}
375+
376+
static int probe_rpc(struct rpc_state *rpc)
377+
{
378+
struct active_request_slot *slot;
379+
struct curl_slist *headers = NULL;
380+
struct strbuf buf = STRBUF_INIT;
381+
int err;
382+
383+
slot = get_active_slot();
384+
385+
headers = curl_slist_append(headers, rpc->hdr_content_type);
386+
headers = curl_slist_append(headers, rpc->hdr_accept);
387+
388+
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
389+
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
390+
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
391+
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
392+
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
393+
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
394+
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
395+
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
396+
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
397+
398+
err = run_slot(slot);
399+
400+
curl_slist_free_all(headers);
401+
strbuf_release(&buf);
402+
return err;
403+
}
404+
359405
static int post_rpc(struct rpc_state *rpc)
360406
{
361407
struct active_request_slot *slot;
362-
struct slot_results results;
363408
struct curl_slist *headers = NULL;
364409
int use_gzip = rpc->gzip_request;
365410
char *gzip_body = NULL;
366-
int err = 0, large_request = 0;
411+
int err, large_request = 0;
367412

368413
/* Try to load the entire request, if we can fit it into the
369414
* allocated buffer space we can use HTTP/1.0 and avoid the
@@ -386,8 +431,13 @@ static int post_rpc(struct rpc_state *rpc)
386431
rpc->len += n;
387432
}
388433

434+
if (large_request) {
435+
err = probe_rpc(rpc);
436+
if (err)
437+
return err;
438+
}
439+
389440
slot = get_active_slot();
390-
slot->results = &results;
391441

392442
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
393443
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
@@ -401,7 +451,7 @@ static int post_rpc(struct rpc_state *rpc)
401451
/* The request body is large and the size cannot be predicted.
402452
* We must use chunked encoding to send it.
403453
*/
404-
headers = curl_slist_append(headers, "Expect: 100-continue");
454+
headers = curl_slist_append(headers, "Expect:");
405455
headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
406456
rpc->initial_buffer = 1;
407457
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
@@ -475,13 +525,7 @@ static int post_rpc(struct rpc_state *rpc)
475525
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
476526
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
477527

478-
slot->curl_result = curl_easy_perform(slot->curl);
479-
finish_active_slot(slot);
480-
481-
if (results.curl_result != CURLE_OK) {
482-
err |= error("RPC failed; result=%d, HTTP code = %ld",
483-
results.curl_result, results.http_code);
484-
}
528+
err = run_slot(slot);
485529

486530
curl_slist_free_all(headers);
487531
free(gzip_body);

0 commit comments

Comments
 (0)